96 lines · plain
1; NOTE: Assertions have been autogenerated by utils/update_test_checks.py UTC_ARGS: --version 52; RUN: opt -passes=gvn -S < %s | FileCheck --check-prefixes=CHECK,MDEP %s3; RUN: opt -passes='gvn<memoryssa>' -S < %s | FileCheck --check-prefixes=CHECK,MSSA %s4 5; C source:6;7; void f(int x) {8; if (x != 1)9; puts (x == 2 ? "a" : "b");10; for (;;) {11; puts("step 1");12; if (x == 2)13; continue;14; printf("step 2: %d\n", x);15; }16; }17;18; If we PRE %cmp3, CodeGenPrepare won't be able to sink the compare down to its19; uses, and we are forced to keep both %x and %cmp3 in registers in the loop.20;21; It is just as cheap to recompute the icmp against %x as it is to compare a22; GPR against 0. On x86-64, the br i1 %cmp3 becomes:23;24; testb %r12b, %r12b25; jne LBB0_326;27; The sunk icmp is:28;29; cmpl $2, %ebx30; je LBB0_331;32; This is just as good, and it doesn't require a separate register.33;34; CHECK-NOT: phi i135 36@.str = private unnamed_addr constant [2 x i8] c"a\00", align 137@.str1 = private unnamed_addr constant [2 x i8] c"b\00", align 138@.str2 = private unnamed_addr constant [7 x i8] c"step 1\00", align 139@.str3 = private unnamed_addr constant [12 x i8] c"step 2: %d\0A\00", align 140 41define void @f(i32 %x) noreturn nounwind uwtable ssp {42; CHECK-LABEL: define void @f(43; CHECK-SAME: i32 [[X:%.*]]) #[[ATTR0:[0-9]+]] {44; CHECK-NEXT: [[ENTRY:.*:]]45; CHECK-NEXT: [[CMP:%.*]] = icmp eq i32 [[X]], 146; CHECK-NEXT: br i1 [[CMP]], label %[[FOR_COND_PREHEADER:.*]], label %[[IF_THEN:.*]]47; CHECK: [[IF_THEN]]:48; CHECK-NEXT: [[CMP1:%.*]] = icmp eq i32 [[X]], 249; CHECK-NEXT: [[COND:%.*]] = select i1 [[CMP1]], ptr @.str, ptr @.str150; CHECK-NEXT: [[CALL:%.*]] = tail call i32 @puts(ptr [[COND]]) #[[ATTR1:[0-9]+]]51; CHECK-NEXT: br label %[[FOR_COND_PREHEADER]]52; CHECK: [[FOR_COND_PREHEADER]]:53; CHECK-NEXT: [[CMP3:%.*]] = icmp eq i32 [[X]], 254; CHECK-NEXT: br label %[[FOR_COND:.*]]55; CHECK: [[FOR_COND]]:56; CHECK-NEXT: [[CALL2:%.*]] = tail call i32 @puts(ptr @.str2) #[[ATTR1]]57; CHECK-NEXT: br i1 [[CMP3]], label %[[FOR_COND_BACKEDGE:.*]], label %[[IF_END5:.*]]58; CHECK: [[IF_END5]]:59; CHECK-NEXT: [[CALL6:%.*]] = tail call i32 (ptr, ...) @printf(ptr @.str3, i32 [[X]]) #[[ATTR1]]60; CHECK-NEXT: br label %[[FOR_COND_BACKEDGE]]61; CHECK: [[FOR_COND_BACKEDGE]]:62; CHECK-NEXT: br label %[[FOR_COND]]63;64entry:65 %cmp = icmp eq i32 %x, 166 br i1 %cmp, label %for.cond.preheader, label %if.then67 68if.then: ; preds = %entry69 %cmp1 = icmp eq i32 %x, 270 %cond = select i1 %cmp1, ptr @.str, ptr @.str171 %call = tail call i32 @puts(ptr %cond) nounwind72 br label %for.cond.preheader73 74for.cond.preheader: ; preds = %entry, %if.then75 %cmp3 = icmp eq i32 %x, 276 br label %for.cond77 78for.cond: ; preds = %for.cond.backedge, %for.cond.preheader79 %call2 = tail call i32 @puts(ptr @.str2) nounwind80 br i1 %cmp3, label %for.cond.backedge, label %if.end581 82if.end5: ; preds = %for.cond83 %call6 = tail call i32 (ptr, ...) @printf(ptr @.str3, i32 %x) nounwind84 br label %for.cond.backedge85 86for.cond.backedge: ; preds = %if.end5, %for.cond87 br label %for.cond88}89 90declare i32 @puts(ptr nocapture) nounwind91 92declare i32 @printf(ptr nocapture, ...) nounwind93;; NOTE: These prefixes are unused and the list is autogenerated. Do not add tests below this line:94; MDEP: {{.*}}95; MSSA: {{.*}}96