[OpenMP] Add flag for preventing the extension to 64 bits for the collapse loop counter
Summary: Introduce a compiler flag for cases when the user knows that the collapsed loop counter can be safely represented using at most 32 bits. This will prevent the emission of expensive mathematical operations (such as the div operation) on the iteration variable using 64 bits where 32 bit operations are sufficient.
Reviewers: ABataev, caomhin
Reviewed By: ABataev
Subscribers: hfinkel, kkwli0, guansong, cfe-commits
Differential Revision: https://reviews.llvm.org/D55928
llvm-svn: 350758
diff --git a/clang/lib/Frontend/CompilerInvocation.cpp b/clang/lib/Frontend/CompilerInvocation.cpp
index 04105f0..1e85735 100644
--- a/clang/lib/Frontend/CompilerInvocation.cpp
+++ b/clang/lib/Frontend/CompilerInvocation.cpp
@@ -2846,6 +2846,11 @@
Opts.OpenMPCUDABlocksPerSM, Diags);
}
+ // Prevent auto-widening the representation of loop counters during an
+ // OpenMP collapse clause.
+ Opts.OpenMPOptimisticCollapse =
+ Args.hasArg(options::OPT_fopenmp_optimistic_collapse) ? 1 : 0;
+
// Get the OpenMP target triples if any.
if (Arg *A = Args.getLastArg(options::OPT_fopenmp_targets_EQ)) {