[llvm-branch-commits] [llvm] f748e92 - [NewPM] Run non-trivial loop unswitching under -O2/3/s/z

Arthur Eubanks via llvm-branch-commits llvm-branch-commits at lists.llvm.org
Tue Jan 12 11:08:59 PST 2021


Author: Arthur Eubanks
Date: 2021-01-12T11:04:40-08:00
New Revision: f748e92295515ea7b39cd687a718915b559de6ec

URL: https://github.com/llvm/llvm-project/commit/f748e92295515ea7b39cd687a718915b559de6ec
DIFF: https://github.com/llvm/llvm-project/commit/f748e92295515ea7b39cd687a718915b559de6ec.diff

LOG: [NewPM] Run non-trivial loop unswitching under -O2/3/s/z

Fixes https://bugs.llvm.org/show_bug.cgi?id=48715.

Reviewed By: asbirlea

Differential Revision: https://reviews.llvm.org/D94448

Added: 
    llvm/test/Transforms/SimpleLoopUnswitch/pipeline.ll

Modified: 
    llvm/lib/Passes/PassBuilder.cpp
    llvm/test/Transforms/LoopUnroll/opt-levels.ll

Removed: 
    


################################################################################
diff  --git a/llvm/lib/Passes/PassBuilder.cpp b/llvm/lib/Passes/PassBuilder.cpp
index 527d19d63589..0d7f442f9ff4 100644
--- a/llvm/lib/Passes/PassBuilder.cpp
+++ b/llvm/lib/Passes/PassBuilder.cpp
@@ -724,7 +724,7 @@ PassBuilder::buildFunctionSimplificationPipeline(OptimizationLevel Level,
   LPM1.addPass(LoopRotatePass(Level != OptimizationLevel::Oz));
   // TODO: Investigate promotion cap for O1.
   LPM1.addPass(LICMPass(PTO.LicmMssaOptCap, PTO.LicmMssaNoAccForPromotionCap));
-  LPM1.addPass(SimpleLoopUnswitchPass());
+  LPM1.addPass(SimpleLoopUnswitchPass(/* NonTrivial */ true));
   LPM2.addPass(LoopIdiomRecognizePass());
   LPM2.addPass(IndVarSimplifyPass());
 

diff  --git a/llvm/test/Transforms/LoopUnroll/opt-levels.ll b/llvm/test/Transforms/LoopUnroll/opt-levels.ll
index ed0abc7672e0..f268d9bd5506 100644
--- a/llvm/test/Transforms/LoopUnroll/opt-levels.ll
+++ b/llvm/test/Transforms/LoopUnroll/opt-levels.ll
@@ -7,10 +7,10 @@
 ; the behavior, we artificially disable unrolling for anything but O3 by setting
 ; the default threshold to 0.
 
-; O3:     loop2.preheader
-; O2-NOT: loop2.preheader
-; Os-NOT: loop2.preheader
-; Oz-NOT: loop2.preheader
+; O3:     loop1.preheader
+; O2-NOT: loop1.preheader
+; Os-NOT: loop1.preheader
+; Oz-NOT: loop1.preheader
 
 define void @unroll(i32 %iter, i32* %addr1, i32* %addr2) nounwind {
 entry:

diff  --git a/llvm/test/Transforms/SimpleLoopUnswitch/pipeline.ll b/llvm/test/Transforms/SimpleLoopUnswitch/pipeline.ll
new file mode 100644
index 000000000000..953b407cccd9
--- /dev/null
+++ b/llvm/test/Transforms/SimpleLoopUnswitch/pipeline.ll
@@ -0,0 +1,39 @@
+; RUN: opt < %s -S -passes="default<O1>" | FileCheck %s -check-prefix=O1
+; RUN: opt < %s -S -passes="default<O2>" | FileCheck %s -check-prefix=O2
+
+declare i32 @a()
+declare i32 @b()
+declare i32 @c()
+
+; O1-NOT: loop_begin.us:
+; O2: loop_begin.us:
+
+define i32 @test1(i1* %ptr, i1 %cond1, i1 %cond2) {
+entry:
+  br label %loop_begin
+
+loop_begin:
+  br i1 %cond1, label %loop_a, label %loop_b
+
+loop_a:
+  call i32 @a()
+  br label %latch
+
+loop_b:
+  br i1 %cond2, label %loop_b_a, label %loop_b_b
+
+loop_b_a:
+  call i32 @b()
+  br label %latch
+
+loop_b_b:
+  call i32 @c()
+  br label %latch
+
+latch:
+  %v = load i1, i1* %ptr
+  br i1 %v, label %loop_begin, label %loop_exit
+
+loop_exit:
+  ret i32 0
+}


        


More information about the llvm-branch-commits mailing list