1 ; 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 ; Don't simplify unconditional branches from empty blocks in simplifyCFG 6 ; until late in the pipeline because it can destroy canonical loop structure. 7 8 define i1 @PR33605(i32 %a, i32 %b, i32* %c) { 9 ; ALL-LABEL: @PR33605( 10 ; ALL-NEXT: for.body: 11 ; ALL-NEXT: [[OR:%.*]] = or i32 [[B:%.*]], [[A:%.*]] 12 ; ALL-NEXT: [[ARRAYIDX:%.*]] = getelementptr inbounds i32, i32* [[C:%.*]], i64 1 13 ; ALL-NEXT: [[TMP0:%.*]] = load i32, i32* [[ARRAYIDX]], align 4 14 ; ALL-NEXT: [[CMP:%.*]] = icmp eq i32 [[OR]], [[TMP0]] 15 ; ALL-NEXT: br i1 [[CMP]], label [[IF_END:%.*]], label [[IF_THEN:%.*]] 16 ; ALL: if.then: 17 ; ALL-NEXT: store i32 [[OR]], i32* [[ARRAYIDX]], align 4 18 ; ALL-NEXT: tail call void @foo() 19 ; ALL-NEXT: br label [[IF_END]] 20 ; ALL: if.end: 21 ; ALL-NEXT: [[CHANGED_1_OFF0:%.*]] = phi i1 [ true, [[IF_THEN]] ], [ false, [[FOR_BODY:%.*]] ] 22 ; ALL-NEXT: [[TMP1:%.*]] = load i32, i32* [[C]], align 4 23 ; ALL-NEXT: [[CMP_1:%.*]] = icmp eq i32 [[OR]], [[TMP1]] 24 ; ALL-NEXT: br i1 [[CMP_1]], label [[IF_END_1:%.*]], label [[IF_THEN_1:%.*]] 25 ; ALL: if.then.1: 26 ; ALL-NEXT: store i32 [[OR]], i32* [[C]], align 4 27 ; ALL-NEXT: tail call void @foo() 28 ; ALL-NEXT: br label [[IF_END_1]] 29 ; ALL: if.end.1: 30 ; ALL-NEXT: [[CHANGED_1_OFF0_1:%.*]] = phi i1 [ true, [[IF_THEN_1]] ], [ [[CHANGED_1_OFF0]], [[IF_END]] ] 31 ; ALL-NEXT: ret i1 [[CHANGED_1_OFF0_1]] 32 ; 33 entry: 34 br label %for.cond 35 36 for.cond: 37 %i.0 = phi i32 [ 2, %entry ], [ %dec, %if.end ] 38 %changed.0.off0 = phi i1 [ false, %entry ], [ %changed.1.off0, %if.end ] 39 %dec = add nsw i32 %i.0, -1 40 %tobool = icmp eq i32 %i.0, 0 41 br i1 %tobool, label %for.cond.cleanup, label %for.body 42 43 for.cond.cleanup: 44 %changed.0.off0.lcssa = phi i1 [ %changed.0.off0, %for.cond ] 45 ret i1 %changed.0.off0.lcssa 46 47 for.body: 48 %or = or i32 %a, %b 49 %idxprom = sext i32 %dec to i64 50 %arrayidx = getelementptr inbounds i32, i32* %c, i64 %idxprom 51 %0 = load i32, i32* %arrayidx, align 4 52 %cmp = icmp eq i32 %or, %0 53 br i1 %cmp, label %if.end, label %if.then 54 55 if.then: 56 store i32 %or, i32* %arrayidx, align 4 57 call void @foo() 58 br label %if.end 59 60 if.end: 61 %changed.1.off0 = phi i1 [ true, %if.then ], [ %changed.0.off0, %for.body ] 62 br label %for.cond 63 } 64 65 declare void @foo() 66 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: [[XI_YI:%.*]] = select i1 [[CMP]], double [[XI]], double [[YI]] 80 ; ALL-NEXT: ret double [[XI_YI]] 81 ; 82 entry: 83 %xi_ptr = getelementptr double, double* %x, i64 %i 84 %yi_ptr = getelementptr double, double* %y, i64 %i 85 %xi = load double, double* %xi_ptr 86 %yi = load double, double* %yi_ptr 87 %cmp = fcmp ogt double %xi, %yi 88 br i1 %cmp, label %if, label %else 89 90 if: 91 %xi_ptr_again = getelementptr double, double* %x, i64 %i 92 %xi_again = load double, double* %xi_ptr_again 93 br label %end 94 95 else: 96 %yi_ptr_again = getelementptr double, double* %y, i64 %i 97 %yi_again = load double, double* %yi_ptr_again 98 br label %end 99 100 end: 101 %max = phi double [ %xi_again, %if ], [ %yi_again, %else ] 102 ret double %max 103 } 104 105