brintos

brintos / llvm-project-archived public Read only

0
0
Text · 3.2 KiB · 8e4e5f8 Raw
92 lines · plain
1; NOTE: Assertions have been autogenerated by utils/update_test_checks.py UTC_ARGS: --version 42; RUN: opt -passes=newgvn -S < %s | FileCheck %s3 4; C source:5;6;   void f(int x) {7;     if (x != 1)8;       puts (x == 2 ? "a" : "b");9;     for (;;) {10;       puts("step 1");11;       if (x == 2)12;         continue;13;       printf("step 2: %d\n", x);14;     }15;   }16;17; If we PRE %cmp3, CodeGenPrepare won't be able to sink the compare down to its18; uses, and we are forced to keep both %x and %cmp3 in registers in the loop.19;20; It is just as cheap to recompute the icmp against %x as it is to compare a21; GPR against 0. On x86-64, the br i1 %cmp3 becomes:22;23;   testb %r12b, %r12b24;   jne	LBB0_325;26; The sunk icmp is:27;28;   cmpl $2, %ebx29;   je	LBB0_330;31; This is just as good, and it doesn't require a separate register.32;33; CHECK-NOT: phi i134 35@.str = private unnamed_addr constant [2 x i8] c"a\00", align 136@.str1 = private unnamed_addr constant [2 x i8] c"b\00", align 137@.str2 = private unnamed_addr constant [7 x i8] c"step 1\00", align 138@.str3 = private unnamed_addr constant [12 x i8] c"step 2: %d\0A\00", align 139 40define void @f(i32 %x) noreturn nounwind uwtable ssp {41; CHECK-LABEL: define void @f(42; CHECK-SAME: i32 [[X:%.*]]) #[[ATTR0:[0-9]+]] {43; CHECK-NEXT:  entry:44; CHECK-NEXT:    [[CMP:%.*]] = icmp eq i32 [[X]], 145; CHECK-NEXT:    br i1 [[CMP]], label [[FOR_COND_PREHEADER:%.*]], label [[IF_THEN:%.*]]46; CHECK:       if.then:47; CHECK-NEXT:    [[CMP1:%.*]] = icmp eq i32 [[X]], 248; CHECK-NEXT:    [[COND:%.*]] = select i1 [[CMP1]], ptr @.str, ptr @.str149; CHECK-NEXT:    [[CALL:%.*]] = tail call i32 @puts(ptr [[COND]]) #[[ATTR1:[0-9]+]]50; CHECK-NEXT:    br label [[FOR_COND_PREHEADER]]51; CHECK:       for.cond.preheader:52; CHECK-NEXT:    [[CMP3:%.*]] = icmp eq i32 [[X]], 253; CHECK-NEXT:    br label [[FOR_COND:%.*]]54; CHECK:       for.cond:55; CHECK-NEXT:    [[CALL2:%.*]] = tail call i32 @puts(ptr @.str2) #[[ATTR1]]56; CHECK-NEXT:    br i1 [[CMP3]], label [[FOR_COND_BACKEDGE:%.*]], label [[IF_END5:%.*]]57; CHECK:       if.end5:58; CHECK-NEXT:    [[CALL6:%.*]] = tail call i32 (ptr, ...) @printf(ptr @.str3, i32 [[X]]) #[[ATTR1]]59; CHECK-NEXT:    br label [[FOR_COND_BACKEDGE]]60; CHECK:       for.cond.backedge:61; CHECK-NEXT:    br label [[FOR_COND]]62;63entry:64  %cmp = icmp eq i32 %x, 165  br i1 %cmp, label %for.cond.preheader, label %if.then66 67if.then:                                          ; preds = %entry68  %cmp1 = icmp eq i32 %x, 269  %cond = select i1 %cmp1, ptr @.str, ptr @.str170  %call = tail call i32 @puts(ptr %cond) nounwind71  br label %for.cond.preheader72 73for.cond.preheader:                               ; preds = %entry, %if.then74  %cmp3 = icmp eq i32 %x, 275  br label %for.cond76 77for.cond:                                         ; preds = %for.cond.backedge, %for.cond.preheader78  %call2 = tail call i32 @puts(ptr @.str2) nounwind79  br i1 %cmp3, label %for.cond.backedge, label %if.end580 81if.end5:                                          ; preds = %for.cond82  %call6 = tail call i32 (ptr, ...) @printf(ptr @.str3, i32 %x) nounwind83  br label %for.cond.backedge84 85for.cond.backedge:                                ; preds = %if.end5, %for.cond86  br label %for.cond87}88 89declare i32 @puts(ptr nocapture) nounwind90 91declare i32 @printf(ptr nocapture, ...) nounwind92