Skip to content

Commit ce7676b

Browse files
committed
Cherry-pick r317444 to google/testing.
git-svn-id: https://llvm.org/svn/llvm-project/llvm/branches/google/testing@317857 91177308-0d34-0410-b5e6-96231b3b80d8
1 parent dc4b1c5 commit ce7676b

File tree

3 files changed

+65
-81
lines changed

3 files changed

+65
-81
lines changed

include/llvm/Transforms/Scalar/SimplifyCFG.h

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -31,16 +31,16 @@ class SimplifyCFGPass : public PassInfoMixin<SimplifyCFGPass> {
3131
SimplifyCFGOptions Options;
3232

3333
public:
34-
/// The default constructor sets the pass options to create canonical IR,
35-
/// rather than optimal IR. That is, by default we bypass transformations that
36-
/// are likely to improve performance but make analysis for other passes more
37-
/// difficult.
34+
/// The default constructor sets the pass options to create optimal IR,
35+
/// rather than canonical IR. That is, by default we do transformations that
36+
/// are likely to improve performance but make analysis more difficult.
37+
/// FIXME: This is inverted from what most instantiations of the pass should
38+
/// be.
3839
SimplifyCFGPass()
3940
: SimplifyCFGPass(SimplifyCFGOptions()
40-
.forwardSwitchCondToPhi(false)
41-
.convertSwitchToLookupTable(false)
42-
.needCanonicalLoops(true)) {}
43-
41+
.forwardSwitchCondToPhi(true)
42+
.convertSwitchToLookupTable(true)
43+
.needCanonicalLoops(false)) {}
4444

4545
/// Construct a pass with optional optimizations.
4646
SimplifyCFGPass(const SimplifyCFGOptions &PassOptions);

lib/Passes/PassBuilder.cpp

Lines changed: 2 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -751,13 +751,8 @@ PassBuilder::buildModuleOptimizationPipeline(OptimizationLevel Level,
751751
// Optimize parallel scalar instruction chains into SIMD instructions.
752752
OptimizePM.addPass(SLPVectorizerPass());
753753

754-
// Cleanup after all of the vectorizers. Simplification passes like CVP and
755-
// GVN, loop transforms, and others have already run, so it's now better to
756-
// convert to more optimized IR using more aggressive simplify CFG options.
757-
OptimizePM.addPass(SimplifyCFGPass(SimplifyCFGOptions().
758-
forwardSwitchCondToPhi(true).
759-
convertSwitchToLookupTable(true).
760-
needCanonicalLoops(false)));
754+
// Cleanup after all of the vectorizers.
755+
OptimizePM.addPass(SimplifyCFGPass());
761756
OptimizePM.addPass(InstCombinePass());
762757

763758
// Unroll small loops to hide loop backedge latency and saturate any parallel
Lines changed: 55 additions & 66 deletions
Original file line numberDiff line numberDiff line change
@@ -1,36 +1,63 @@
11
; NOTE: Assertions have been autogenerated by utils/update_test_checks.py
2-
; RUN: opt -O1 -S < %s | FileCheck %s --check-prefix=ALL --check-prefix=OLDPM
3-
; RUN: opt -passes='default<O1>' -S < %s | FileCheck %s --check-prefix=ALL --check-prefix=NEWPM
4-
5-
declare void @foo()
2+
; RUN: opt -O1 -S < %s | FileCheck %s --check-prefix=OLDPM
3+
; RUN: opt -passes='default<O1>' -S < %s | FileCheck %s --check-prefix=NEWPM
64

75
; Don't simplify unconditional branches from empty blocks in simplifyCFG
86
; until late in the pipeline because it can destroy canonical loop structure.
97

8+
; FIXME: The new pass manager is not limiting simplifycfg at any point in the pipeline,
9+
; so it performs a transformation before loop optimizations that is avoided in the old PM.
10+
1011
define i1 @PR33605(i32 %a, i32 %b, i32* %c) {
11-
; ALL-LABEL: @PR33605(
12-
; ALL-NEXT: for.body:
13-
; ALL-NEXT: [[OR:%.*]] = or i32 [[B:%.*]], [[A:%.*]]
14-
; ALL-NEXT: [[ARRAYIDX:%.*]] = getelementptr inbounds i32, i32* [[C:%.*]], i64 1
15-
; ALL-NEXT: [[TMP0:%.*]] = load i32, i32* [[ARRAYIDX]], align 4
16-
; ALL-NEXT: [[CMP:%.*]] = icmp eq i32 [[OR]], [[TMP0]]
17-
; ALL-NEXT: br i1 [[CMP]], label [[IF_END:%.*]], label [[IF_THEN:%.*]]
18-
; ALL: if.then:
19-
; ALL-NEXT: store i32 [[OR]], i32* [[ARRAYIDX]], align 4
20-
; ALL-NEXT: tail call void @foo()
21-
; ALL-NEXT: br label [[IF_END]]
22-
; ALL: if.end:
23-
; ALL-NEXT: [[CHANGED_1_OFF0:%.*]] = phi i1 [ true, [[IF_THEN]] ], [ false, [[FOR_BODY:%.*]] ]
24-
; ALL-NEXT: [[TMP1:%.*]] = load i32, i32* [[C]], align 4
25-
; ALL-NEXT: [[CMP_1:%.*]] = icmp eq i32 [[OR]], [[TMP1]]
26-
; ALL-NEXT: br i1 [[CMP_1]], label [[IF_END_1:%.*]], label [[IF_THEN_1:%.*]]
27-
; ALL: if.then.1:
28-
; ALL-NEXT: store i32 [[OR]], i32* [[C]], align 4
29-
; ALL-NEXT: tail call void @foo()
30-
; ALL-NEXT: br label [[IF_END_1]]
31-
; ALL: if.end.1:
32-
; ALL-NEXT: [[CHANGED_1_OFF0_1:%.*]] = phi i1 [ true, [[IF_THEN_1]] ], [ [[CHANGED_1_OFF0]], [[IF_END]] ]
33-
; ALL-NEXT: ret i1 [[CHANGED_1_OFF0_1]]
12+
; OLDPM-LABEL: @PR33605(
13+
; OLDPM-NEXT: for.body:
14+
; OLDPM-NEXT: [[OR:%.*]] = or i32 [[B:%.*]], [[A:%.*]]
15+
; OLDPM-NEXT: [[ARRAYIDX:%.*]] = getelementptr inbounds i32, i32* [[C:%.*]], i64 1
16+
; OLDPM-NEXT: [[TMP0:%.*]] = load i32, i32* [[ARRAYIDX]], align 4
17+
; OLDPM-NEXT: [[CMP:%.*]] = icmp eq i32 [[OR]], [[TMP0]]
18+
; OLDPM-NEXT: br i1 [[CMP]], label [[IF_END:%.*]], label [[IF_THEN:%.*]]
19+
; OLDPM: if.then:
20+
; OLDPM-NEXT: store i32 [[OR]], i32* [[ARRAYIDX]], align 4
21+
; OLDPM-NEXT: tail call void @foo()
22+
; OLDPM-NEXT: br label [[IF_END]]
23+
; OLDPM: if.end:
24+
; OLDPM-NEXT: [[CHANGED_1_OFF0:%.*]] = phi i1 [ true, [[IF_THEN]] ], [ false, [[FOR_BODY:%.*]] ]
25+
; OLDPM-NEXT: [[TMP1:%.*]] = load i32, i32* [[C]], align 4
26+
; OLDPM-NEXT: [[CMP_1:%.*]] = icmp eq i32 [[OR]], [[TMP1]]
27+
; OLDPM-NEXT: br i1 [[CMP_1]], label [[IF_END_1:%.*]], label [[IF_THEN_1:%.*]]
28+
; OLDPM: if.then.1:
29+
; OLDPM-NEXT: store i32 [[OR]], i32* [[C]], align 4
30+
; OLDPM-NEXT: tail call void @foo()
31+
; OLDPM-NEXT: br label [[IF_END_1]]
32+
; OLDPM: if.end.1:
33+
; OLDPM-NEXT: [[CHANGED_1_OFF0_1:%.*]] = phi i1 [ true, [[IF_THEN_1]] ], [ [[CHANGED_1_OFF0]], [[IF_END]] ]
34+
; OLDPM-NEXT: ret i1 [[CHANGED_1_OFF0_1]]
35+
;
36+
; NEWPM-LABEL: @PR33605(
37+
; NEWPM-NEXT: entry:
38+
; NEWPM-NEXT: [[OR:%.*]] = or i32 [[B:%.*]], [[A:%.*]]
39+
; NEWPM-NEXT: br label [[FOR_COND_OUTER:%.*]]
40+
; NEWPM: for.cond.outer:
41+
; NEWPM-NEXT: [[I_0_PH:%.*]] = phi i32 [ [[DEC:%.*]], [[IF_THEN:%.*]] ], [ 2, [[ENTRY:%.*]] ]
42+
; NEWPM-NEXT: [[CHANGED_0_OFF0_PH:%.*]] = phi i1 [ true, [[IF_THEN]] ], [ false, [[ENTRY]] ]
43+
; NEWPM-NEXT: br label [[FOR_COND:%.*]]
44+
; NEWPM: for.cond:
45+
; NEWPM-NEXT: [[I_0:%.*]] = phi i32 [ [[DEC]], [[FOR_BODY:%.*]] ], [ [[I_0_PH]], [[FOR_COND_OUTER]] ]
46+
; NEWPM-NEXT: [[DEC]] = add nsw i32 [[I_0]], -1
47+
; NEWPM-NEXT: [[TOBOOL:%.*]] = icmp eq i32 [[I_0]], 0
48+
; NEWPM-NEXT: br i1 [[TOBOOL]], label [[FOR_COND_CLEANUP:%.*]], label [[FOR_BODY]]
49+
; NEWPM: for.cond.cleanup:
50+
; NEWPM-NEXT: ret i1 [[CHANGED_0_OFF0_PH]]
51+
; NEWPM: for.body:
52+
; NEWPM-NEXT: [[IDXPROM:%.*]] = sext i32 [[DEC]] to i64
53+
; NEWPM-NEXT: [[ARRAYIDX:%.*]] = getelementptr inbounds i32, i32* [[C:%.*]], i64 [[IDXPROM]]
54+
; NEWPM-NEXT: [[TMP0:%.*]] = load i32, i32* [[ARRAYIDX]], align 4
55+
; NEWPM-NEXT: [[CMP:%.*]] = icmp eq i32 [[OR]], [[TMP0]]
56+
; NEWPM-NEXT: br i1 [[CMP]], label [[FOR_COND]], label [[IF_THEN]]
57+
; NEWPM: if.then:
58+
; NEWPM-NEXT: store i32 [[OR]], i32* [[ARRAYIDX]], align 4
59+
; NEWPM-NEXT: tail call void @foo()
60+
; NEWPM-NEXT: br label [[FOR_COND_OUTER]]
3461
;
3562
entry:
3663
br label %for.cond
@@ -64,43 +91,5 @@ if.end:
6491
br label %for.cond
6592
}
6693

67-
; PR34603 - https://bugs.llvm.org/show_bug.cgi?id=34603
68-
; We should have a select of doubles, not a select of double pointers.
69-
; SimplifyCFG should not flatten this before early-cse has a chance to eliminate redundant ops.
70-
71-
define double @max_of_loads(double* %x, double* %y, i64 %i) {
72-
; ALL-LABEL: @max_of_loads(
73-
; ALL-NEXT: entry:
74-
; ALL-NEXT: [[XI_PTR:%.*]] = getelementptr double, double* [[X:%.*]], i64 [[I:%.*]]
75-
; ALL-NEXT: [[YI_PTR:%.*]] = getelementptr double, double* [[Y:%.*]], i64 [[I]]
76-
; ALL-NEXT: [[XI:%.*]] = load double, double* [[XI_PTR]], align 8
77-
; ALL-NEXT: [[YI:%.*]] = load double, double* [[YI_PTR]], align 8
78-
; ALL-NEXT: [[CMP:%.*]] = fcmp ogt double [[XI]], [[YI]]
79-
; ALL-NEXT: [[Y_SINK:%.*]] = select i1 [[CMP]], double* [[X]], double* [[Y]]
80-
; ALL-NEXT: [[YI_PTR_AGAIN:%.*]] = getelementptr double, double* [[Y_SINK]], i64 [[I]]
81-
; ALL-NEXT: [[YI_AGAIN:%.*]] = load double, double* [[YI_PTR_AGAIN]], align 8
82-
; ALL-NEXT: ret double [[YI_AGAIN]]
83-
;
84-
entry:
85-
%xi_ptr = getelementptr double, double* %x, i64 %i
86-
%yi_ptr = getelementptr double, double* %y, i64 %i
87-
%xi = load double, double* %xi_ptr
88-
%yi = load double, double* %yi_ptr
89-
%cmp = fcmp ogt double %xi, %yi
90-
br i1 %cmp, label %if, label %else
91-
92-
if:
93-
%xi_ptr_again = getelementptr double, double* %x, i64 %i
94-
%xi_again = load double, double* %xi_ptr_again
95-
br label %end
96-
97-
else:
98-
%yi_ptr_again = getelementptr double, double* %y, i64 %i
99-
%yi_again = load double, double* %yi_ptr_again
100-
br label %end
101-
102-
end:
103-
%max = phi double [ %xi_again, %if ], [ %yi_again, %else ]
104-
ret double %max
105-
}
94+
declare void @foo()
10695

0 commit comments

Comments
 (0)