echristo created this revision.
echristo added reviewers: chandlerc, hfinkel, asbirlea.
Herald added subscribers: llvm-commits, cfe-commits, hiraditya, mcrosier.
Herald added projects: clang, LLVM.
echristo updated this revision to Diff 234656.
echristo added a comment.

Formatting and parens changes.


Last we looked at this and couldn't come up with a reason to change it, but 
with a pragma for full loop unrolling we bypass every other loop unroll and 
then fail to fully unroll a loop when the pragma is set.

Move the OnlyWhenForced out of the check and into the initialization of the 
full unroll pass in the new pass manager. This doesn't show up with the old 
pass manager.

Tested with check-clang and check-llvm.


Repository:
  rG LLVM Github Monorepo

https://reviews.llvm.org/D71687

Files:
  clang/test/Misc/loop-opt-setup.c
  llvm/lib/Passes/PassBuilder.cpp


Index: llvm/lib/Passes/PassBuilder.cpp
===================================================================
--- llvm/lib/Passes/PassBuilder.cpp
+++ llvm/lib/Passes/PassBuilder.cpp
@@ -478,10 +478,10 @@
   // Do not enable unrolling in PreLinkThinLTO phase during sample PGO
   // because it changes IR to makes profile annotation in back compile
   // inaccurate.
-  if ((Phase != ThinLTOPhase::PreLink || !PGOOpt ||
-       PGOOpt->Action != PGOOptions::SampleUse) &&
-      PTO.LoopUnrolling)
-    LPM2.addPass(LoopFullUnrollPass(Level, /*OnlyWhenForced=*/false,
+  if (Phase != ThinLTOPhase::PreLink || !PGOOpt ||
+      PGOOpt->Action != PGOOptions::SampleUse)
+    LPM2.addPass(LoopFullUnrollPass(Level,
+                                    /*OnlyWhenForced=*/!PTO.LoopUnrolling,
                                     PTO.ForgetAllSCEVInLoopUnroll));
 
   for (auto &C : LoopOptimizerEndEPCallbacks)
Index: clang/test/Misc/loop-opt-setup.c
===================================================================
--- clang/test/Misc/loop-opt-setup.c
+++ clang/test/Misc/loop-opt-setup.c
@@ -8,5 +8,13 @@
     a[i] = b += 2;
   return b;
 }
+
+int B(void) {
+#pragma clang loop unroll(full)
+  for (int i = 0; i < 16; ++i)
+    a[i] = b += 2;
+  return b;
+}
+
 // CHECK-NOT: br i1
 


Index: llvm/lib/Passes/PassBuilder.cpp
===================================================================
--- llvm/lib/Passes/PassBuilder.cpp
+++ llvm/lib/Passes/PassBuilder.cpp
@@ -478,10 +478,10 @@
   // Do not enable unrolling in PreLinkThinLTO phase during sample PGO
   // because it changes IR to makes profile annotation in back compile
   // inaccurate.
-  if ((Phase != ThinLTOPhase::PreLink || !PGOOpt ||
-       PGOOpt->Action != PGOOptions::SampleUse) &&
-      PTO.LoopUnrolling)
-    LPM2.addPass(LoopFullUnrollPass(Level, /*OnlyWhenForced=*/false,
+  if (Phase != ThinLTOPhase::PreLink || !PGOOpt ||
+      PGOOpt->Action != PGOOptions::SampleUse)
+    LPM2.addPass(LoopFullUnrollPass(Level,
+                                    /*OnlyWhenForced=*/!PTO.LoopUnrolling,
                                     PTO.ForgetAllSCEVInLoopUnroll));
 
   for (auto &C : LoopOptimizerEndEPCallbacks)
Index: clang/test/Misc/loop-opt-setup.c
===================================================================
--- clang/test/Misc/loop-opt-setup.c
+++ clang/test/Misc/loop-opt-setup.c
@@ -8,5 +8,13 @@
     a[i] = b += 2;
   return b;
 }
+
+int B(void) {
+#pragma clang loop unroll(full)
+  for (int i = 0; i < 16; ++i)
+    a[i] = b += 2;
+  return b;
+}
+
 // CHECK-NOT: br i1
 
_______________________________________________
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits

Reply via email to