[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
This commit is contained in:
Arthur Eubanks 2021-01-11 13:50:52 -08:00
parent 4718ec0166
commit f748e92295
3 changed files with 44 additions and 5 deletions

View File

@ -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());

View File

@ -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:

View File

@ -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
}