llvm.org GIT mirror llvm / c8200b7
[PassManager, SimplifyCFG] Revert r316908 and r316869. These cause Clang to crash with a segfault. See PR35210 for details. git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@317444 91177308-0d34-0410-b5e6-96231b3b80d8 David L. Jones 1 year, 10 months ago
3 changed file(s) with 65 addition(s) and 81 deletion(s). Raw diff Collapse all Expand all
3030 SimplifyCFGOptions Options;
3131
3232 public:
33 /// The default constructor sets the pass options to create canonical IR,
34 /// rather than optimal IR. That is, by default we bypass transformations that
35 /// are likely to improve performance but make analysis for other passes more
36 /// difficult.
33 /// The default constructor sets the pass options to create optimal IR,
34 /// rather than canonical IR. That is, by default we do transformations that
35 /// are likely to improve performance but make analysis more difficult.
36 /// FIXME: This is inverted from what most instantiations of the pass should
37 /// be.
3738 SimplifyCFGPass()
3839 : SimplifyCFGPass(SimplifyCFGOptions()
39 .forwardSwitchCondToPhi(false)
40 .convertSwitchToLookupTable(false)
41 .needCanonicalLoops(true)) {}
42
40 .forwardSwitchCondToPhi(true)
41 .convertSwitchToLookupTable(true)
42 .needCanonicalLoops(false)) {}
4343
4444 /// Construct a pass with optional optimizations.
4545 SimplifyCFGPass(const SimplifyCFGOptions &PassOptions);
754754 // Optimize parallel scalar instruction chains into SIMD instructions.
755755 OptimizePM.addPass(SLPVectorizerPass());
756756
757 // Cleanup after all of the vectorizers. Simplification passes like CVP and
758 // GVN, loop transforms, and others have already run, so it's now better to
759 // convert to more optimized IR using more aggressive simplify CFG options.
760 OptimizePM.addPass(SimplifyCFGPass(SimplifyCFGOptions().
761 forwardSwitchCondToPhi(true).
762 convertSwitchToLookupTable(true).
763 needCanonicalLoops(false)));
757 // Cleanup after all of the vectorizers.
758 OptimizePM.addPass(SimplifyCFGPass());
764759 OptimizePM.addPass(InstCombinePass());
765760
766761 // Unroll small loops to hide loop backedge latency and saturate any parallel
0 ; NOTE: Assertions have been autogenerated by utils/update_test_checks.py
1 ; RUN: opt -O1 -S < %s | FileCheck %s --check-prefix=ALL --check-prefix=OLDPM
2 ; RUN: opt -passes='default' -S < %s | FileCheck %s --check-prefix=ALL --check-prefix=NEWPM
3
4 declare void @foo()
1 ; RUN: opt -O1 -S < %s | FileCheck %s --check-prefix=OLDPM
2 ; RUN: opt -passes='default' -S < %s | FileCheck %s --check-prefix=NEWPM
53
64 ; Don't simplify unconditional branches from empty blocks in simplifyCFG
75 ; until late in the pipeline because it can destroy canonical loop structure.
86
7 ; FIXME: The new pass manager is not limiting simplifycfg at any point in the pipeline,
8 ; so it performs a transformation before loop optimizations that is avoided in the old PM.
9
910 define i1 @PR33605(i32 %a, i32 %b, i32* %c) {
10 ; ALL-LABEL: @PR33605(
11 ; ALL-NEXT: for.body:
12 ; ALL-NEXT: [[OR:%.*]] = or i32 [[B:%.*]], [[A:%.*]]
13 ; ALL-NEXT: [[ARRAYIDX:%.*]] = getelementptr inbounds i32, i32* [[C:%.*]], i64 1
14 ; ALL-NEXT: [[TMP0:%.*]] = load i32, i32* [[ARRAYIDX]], align 4
15 ; ALL-NEXT: [[CMP:%.*]] = icmp eq i32 [[OR]], [[TMP0]]
16 ; ALL-NEXT: br i1 [[CMP]], label [[IF_END:%.*]], label [[IF_THEN:%.*]]
17 ; ALL: if.then:
18 ; ALL-NEXT: store i32 [[OR]], i32* [[ARRAYIDX]], align 4
19 ; ALL-NEXT: tail call void @foo()
20 ; ALL-NEXT: br label [[IF_END]]
21 ; ALL: if.end:
22 ; ALL-NEXT: [[CHANGED_1_OFF0:%.*]] = phi i1 [ true, [[IF_THEN]] ], [ false, [[FOR_BODY:%.*]] ]
23 ; ALL-NEXT: [[TMP1:%.*]] = load i32, i32* [[C]], align 4
24 ; ALL-NEXT: [[CMP_1:%.*]] = icmp eq i32 [[OR]], [[TMP1]]
25 ; ALL-NEXT: br i1 [[CMP_1]], label [[IF_END_1:%.*]], label [[IF_THEN_1:%.*]]
26 ; ALL: if.then.1:
27 ; ALL-NEXT: store i32 [[OR]], i32* [[C]], align 4
28 ; ALL-NEXT: tail call void @foo()
29 ; ALL-NEXT: br label [[IF_END_1]]
30 ; ALL: if.end.1:
31 ; ALL-NEXT: [[CHANGED_1_OFF0_1:%.*]] = phi i1 [ true, [[IF_THEN_1]] ], [ [[CHANGED_1_OFF0]], [[IF_END]] ]
32 ; ALL-NEXT: ret i1 [[CHANGED_1_OFF0_1]]
11 ; OLDPM-LABEL: @PR33605(
12 ; OLDPM-NEXT: for.body:
13 ; OLDPM-NEXT: [[OR:%.*]] = or i32 [[B:%.*]], [[A:%.*]]
14 ; OLDPM-NEXT: [[ARRAYIDX:%.*]] = getelementptr inbounds i32, i32* [[C:%.*]], i64 1
15 ; OLDPM-NEXT: [[TMP0:%.*]] = load i32, i32* [[ARRAYIDX]], align 4
16 ; OLDPM-NEXT: [[CMP:%.*]] = icmp eq i32 [[OR]], [[TMP0]]
17 ; OLDPM-NEXT: br i1 [[CMP]], label [[IF_END:%.*]], label [[IF_THEN:%.*]]
18 ; OLDPM: if.then:
19 ; OLDPM-NEXT: store i32 [[OR]], i32* [[ARRAYIDX]], align 4
20 ; OLDPM-NEXT: tail call void @foo()
21 ; OLDPM-NEXT: br label [[IF_END]]
22 ; OLDPM: if.end:
23 ; OLDPM-NEXT: [[CHANGED_1_OFF0:%.*]] = phi i1 [ true, [[IF_THEN]] ], [ false, [[FOR_BODY:%.*]] ]
24 ; OLDPM-NEXT: [[TMP1:%.*]] = load i32, i32* [[C]], align 4
25 ; OLDPM-NEXT: [[CMP_1:%.*]] = icmp eq i32 [[OR]], [[TMP1]]
26 ; OLDPM-NEXT: br i1 [[CMP_1]], label [[IF_END_1:%.*]], label [[IF_THEN_1:%.*]]
27 ; OLDPM: if.then.1:
28 ; OLDPM-NEXT: store i32 [[OR]], i32* [[C]], align 4
29 ; OLDPM-NEXT: tail call void @foo()
30 ; OLDPM-NEXT: br label [[IF_END_1]]
31 ; OLDPM: if.end.1:
32 ; OLDPM-NEXT: [[CHANGED_1_OFF0_1:%.*]] = phi i1 [ true, [[IF_THEN_1]] ], [ [[CHANGED_1_OFF0]], [[IF_END]] ]
33 ; OLDPM-NEXT: ret i1 [[CHANGED_1_OFF0_1]]
34 ;
35 ; NEWPM-LABEL: @PR33605(
36 ; NEWPM-NEXT: entry:
37 ; NEWPM-NEXT: [[OR:%.*]] = or i32 [[B:%.*]], [[A:%.*]]
38 ; NEWPM-NEXT: br label [[FOR_COND_OUTER:%.*]]
39 ; NEWPM: for.cond.outer:
40 ; NEWPM-NEXT: [[I_0_PH:%.*]] = phi i32 [ [[DEC:%.*]], [[IF_THEN:%.*]] ], [ 2, [[ENTRY:%.*]] ]
41 ; NEWPM-NEXT: [[CHANGED_0_OFF0_PH:%.*]] = phi i1 [ true, [[IF_THEN]] ], [ false, [[ENTRY]] ]
42 ; NEWPM-NEXT: br label [[FOR_COND:%.*]]
43 ; NEWPM: for.cond:
44 ; NEWPM-NEXT: [[I_0:%.*]] = phi i32 [ [[DEC]], [[FOR_BODY:%.*]] ], [ [[I_0_PH]], [[FOR_COND_OUTER]] ]
45 ; NEWPM-NEXT: [[DEC]] = add nsw i32 [[I_0]], -1
46 ; NEWPM-NEXT: [[TOBOOL:%.*]] = icmp eq i32 [[I_0]], 0
47 ; NEWPM-NEXT: br i1 [[TOBOOL]], label [[FOR_COND_CLEANUP:%.*]], label [[FOR_BODY]]
48 ; NEWPM: for.cond.cleanup:
49 ; NEWPM-NEXT: ret i1 [[CHANGED_0_OFF0_PH]]
50 ; NEWPM: for.body:
51 ; NEWPM-NEXT: [[IDXPROM:%.*]] = sext i32 [[DEC]] to i64
52 ; NEWPM-NEXT: [[ARRAYIDX:%.*]] = getelementptr inbounds i32, i32* [[C:%.*]], i64 [[IDXPROM]]
53 ; NEWPM-NEXT: [[TMP0:%.*]] = load i32, i32* [[ARRAYIDX]], align 4
54 ; NEWPM-NEXT: [[CMP:%.*]] = icmp eq i32 [[OR]], [[TMP0]]
55 ; NEWPM-NEXT: br i1 [[CMP]], label [[FOR_COND]], label [[IF_THEN]]
56 ; NEWPM: if.then:
57 ; NEWPM-NEXT: store i32 [[OR]], i32* [[ARRAYIDX]], align 4
58 ; NEWPM-NEXT: tail call void @foo()
59 ; NEWPM-NEXT: br label [[FOR_COND_OUTER]]
3360 ;
3461 entry:
3562 br label %for.cond
6390 br label %for.cond
6491 }
6592
66 ; PR34603 - https://bugs.llvm.org/show_bug.cgi?id=34603
67 ; We should have a select of doubles, not a select of double pointers.
68 ; SimplifyCFG should not flatten this before early-cse has a chance to eliminate redundant ops.
93 declare void @foo()
6994
70 define double @max_of_loads(double* %x, double* %y, i64 %i) {
71 ; ALL-LABEL: @max_of_loads(
72 ; ALL-NEXT: entry:
73 ; ALL-NEXT: [[XI_PTR:%.*]] = getelementptr double, double* [[X:%.*]], i64 [[I:%.*]]
74 ; ALL-NEXT: [[YI_PTR:%.*]] = getelementptr double, double* [[Y:%.*]], i64 [[I]]
75 ; ALL-NEXT: [[XI:%.*]] = load double, double* [[XI_PTR]], align 8
76 ; ALL-NEXT: [[YI:%.*]] = load double, double* [[YI_PTR]], align 8
77 ; ALL-NEXT: [[CMP:%.*]] = fcmp ogt double [[XI]], [[YI]]
78 ; ALL-NEXT: [[Y_SINK:%.*]] = select i1 [[CMP]], double* [[X]], double* [[Y]]
79 ; ALL-NEXT: [[YI_PTR_AGAIN:%.*]] = getelementptr double, double* [[Y_SINK]], i64 [[I]]
80 ; ALL-NEXT: [[YI_AGAIN:%.*]] = load double, double* [[YI_PTR_AGAIN]], align 8
81 ; ALL-NEXT: ret double [[YI_AGAIN]]
82 ;
83 entry:
84 %xi_ptr = getelementptr double, double* %x, i64 %i
85 %yi_ptr = getelementptr double, double* %y, i64 %i
86 %xi = load double, double* %xi_ptr
87 %yi = load double, double* %yi_ptr
88 %cmp = fcmp ogt double %xi, %yi
89 br i1 %cmp, label %if, label %else
90
91 if:
92 %xi_ptr_again = getelementptr double, double* %x, i64 %i
93 %xi_again = load double, double* %xi_ptr_again
94 br label %end
95
96 else:
97 %yi_ptr_again = getelementptr double, double* %y, i64 %i
98 %yi_again = load double, double* %yi_ptr_again
99 br label %end
100
101 end:
102 %max = phi double [ %xi_again, %if ], [ %yi_again, %else ]
103 ret double %max
104 }
105