125 lines · plain
1; NOTE: Assertions have been autogenerated by utils/update_test_checks.py2; RUN: opt -O1 -S < %s | FileCheck %s3; RUN: opt -passes='default<O1>' -S < %s | FileCheck %s4 5; Don't simplify unconditional branches from empty blocks in simplifyCFG6; until late in the pipeline because it can destroy canonical loop structure.7 8define i1 @PR33605(i32 %a, i32 %b, ptr %c) {9; CHECK-LABEL: @PR33605(10; CHECK-NEXT: entry:11; CHECK-NEXT: [[OR:%.*]] = or i32 [[B:%.*]], [[A:%.*]]12; CHECK-NEXT: [[ARRAYIDX:%.*]] = getelementptr inbounds nuw i8, ptr [[C:%.*]], i64 413; CHECK-NEXT: [[TMP0:%.*]] = load i32, ptr [[ARRAYIDX]], align 414; CHECK-NEXT: [[CMP:%.*]] = icmp ne i32 [[OR]], [[TMP0]]15; CHECK-NEXT: br i1 [[CMP]], label [[IF_THEN:%.*]], label [[IF_END:%.*]]16; CHECK: if.then:17; CHECK-NEXT: store i32 [[OR]], ptr [[ARRAYIDX]], align 418; CHECK-NEXT: tail call void @foo()19; CHECK-NEXT: br label [[IF_END]]20; CHECK: if.end:21; CHECK-NEXT: [[TMP1:%.*]] = load i32, ptr [[C]], align 422; CHECK-NEXT: [[CMP_1:%.*]] = icmp eq i32 [[OR]], [[TMP1]]23; CHECK-NEXT: br i1 [[CMP_1]], label [[IF_END_1:%.*]], label [[IF_THEN_1:%.*]]24; CHECK: if.then.1:25; CHECK-NEXT: store i32 [[OR]], ptr [[C]], align 426; CHECK-NEXT: tail call void @foo()27; CHECK-NEXT: br label [[IF_END_1]]28; CHECK: if.end.1:29; CHECK-NEXT: [[CHANGED_1_OFF0_1:%.*]] = phi i1 [ true, [[IF_THEN_1]] ], [ [[CMP]], [[IF_END]] ]30; CHECK-NEXT: ret i1 [[CHANGED_1_OFF0_1]]31;32entry:33 br label %for.cond34 35for.cond:36 %i.0 = phi i32 [ 2, %entry ], [ %dec, %if.end ]37 %changed.0.off0 = phi i1 [ false, %entry ], [ %changed.1.off0, %if.end ]38 %dec = add nsw i32 %i.0, -139 %tobool = icmp eq i32 %i.0, 040 br i1 %tobool, label %for.cond.cleanup, label %for.body41 42for.cond.cleanup:43 %changed.0.off0.lcssa = phi i1 [ %changed.0.off0, %for.cond ]44 ret i1 %changed.0.off0.lcssa45 46for.body:47 %or = or i32 %a, %b48 %idxprom = sext i32 %dec to i6449 %arrayidx = getelementptr inbounds i32, ptr %c, i64 %idxprom50 %0 = load i32, ptr %arrayidx, align 451 %cmp = icmp eq i32 %or, %052 br i1 %cmp, label %if.end, label %if.then53 54if.then:55 store i32 %or, ptr %arrayidx, align 456 call void @foo()57 br label %if.end58 59if.end:60 %changed.1.off0 = phi i1 [ true, %if.then ], [ %changed.0.off0, %for.body ]61 br label %for.cond62}63 64declare void @foo()65 66; PR34603 - https://bugs.llvm.org/show_bug.cgi?id=3460367; 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.69 70define double @max_of_loads(ptr %x, ptr %y, i64 %i) {71; CHECK-LABEL: @max_of_loads(72; CHECK-NEXT: entry:73; CHECK-NEXT: [[XI_PTR:%.*]] = getelementptr double, ptr [[X:%.*]], i64 [[I:%.*]]74; CHECK-NEXT: [[YI_PTR:%.*]] = getelementptr double, ptr [[Y:%.*]], i64 [[I]]75; CHECK-NEXT: [[XI:%.*]] = load double, ptr [[XI_PTR]], align 876; CHECK-NEXT: [[YI:%.*]] = load double, ptr [[YI_PTR]], align 877; CHECK-NEXT: [[CMP:%.*]] = fcmp ogt double [[XI]], [[YI]]78; CHECK-NEXT: [[XI_YI:%.*]] = select i1 [[CMP]], double [[XI]], double [[YI]]79; CHECK-NEXT: ret double [[XI_YI]]80;81entry:82 %xi_ptr = getelementptr double, ptr %x, i64 %i83 %yi_ptr = getelementptr double, ptr %y, i64 %i84 %xi = load double, ptr %xi_ptr85 %yi = load double, ptr %yi_ptr86 %cmp = fcmp ogt double %xi, %yi87 br i1 %cmp, label %if, label %else88 89if:90 %xi_ptr_again = getelementptr double, ptr %x, i64 %i91 %xi_again = load double, ptr %xi_ptr_again92 br label %end93 94else:95 %yi_ptr_again = getelementptr double, ptr %y, i64 %i96 %yi_again = load double, ptr %yi_ptr_again97 br label %end98 99end:100 %max = phi double [ %xi_again, %if ], [ %yi_again, %else ]101 ret double %max102}103 104define i1 @PR58313(i1 %lhs, i1 %rhs) {105; CHECK-LABEL: @PR58313(106; CHECK-NEXT: andandend:107; CHECK-NEXT: [[SPEC_SELECT:%.*]] = xor i1 [[LHS:%.*]], [[RHS:%.*]]108; CHECK-NEXT: ret i1 [[SPEC_SELECT]]109;110andandend:111 %0 = xor i1 %rhs, true112 %andandval = select i1 %lhs, i1 %0, i1 false113 br i1 %andandval, label %ororend, label %oror114 115oror:116 %1 = xor i1 %lhs, true117 %andandval3 = select i1 %1, i1 %rhs, i1 false118 br label %ororend119 120ororend:121 %ororval = phi i1 [ true, %andandend ], [ %andandval3, %oror ]122 ret i1 %ororval123}124 125