brintos

brintos / llvm-project-archived public Read only

0
0
Text · 2.1 KiB · 562aad7 Raw
109 lines · plain
1; RUN: opt -passes=early-cse -earlycse-debug-hash -S < %s | FileCheck %s2; RUN: opt -passes='early-cse<memssa>' -S < %s | FileCheck %s3 4; Can we CSE a known condition to a constant?5define i1 @test(ptr %p) {6; CHECK-LABEL: @test7entry:8  %cnd1 = icmp eq ptr %p, null9  br i1 %cnd1, label %taken, label %untaken10 11taken:12; CHECK-LABEL: taken:13; CHECK-NEXT: ret i1 true14  %cnd2 = icmp eq ptr %p, null15  ret i1 %cnd216 17untaken:18; CHECK-LABEL: untaken:19; CHECK-NEXT: ret i1 false20  %cnd3 = icmp eq ptr %p, null21  ret i1 %cnd322}23 24; We can CSE the condition, but we *don't* know it's value after the merge25define i1 @test_neg1(ptr %p) {26; CHECK-LABEL: @test_neg127entry:28  %cnd1 = icmp eq ptr %p, null29  br i1 %cnd1, label %taken, label %untaken30 31taken:32  br label %merge33 34untaken:35  br label %merge36 37merge:38; CHECK-LABEL: merge:39; CHECK-NEXT: ret i1 %cnd140  %cnd3 = icmp eq ptr %p, null41  ret i1 %cnd342}43 44; Check specifically for a case where we have a unique predecessor, but45; not a single predecessor.  We can not know the value of the condition here.46define i1 @test_neg2(ptr %p) {47; CHECK-LABEL: @test_neg248entry:49  %cnd1 = icmp eq ptr %p, null50  br i1 %cnd1, label %merge, label %merge51 52merge:53; CHECK-LABEL: merge:54; CHECK-NEXT: ret i1 %cnd155  %cnd3 = icmp eq ptr %p, null56  ret i1 %cnd357}58 59; Replace a use rather than CSE60define i1 @test2(ptr %p) {61; CHECK-LABEL: @test262entry:63  %cnd = icmp eq ptr %p, null64  br i1 %cnd, label %taken, label %untaken65 66taken:67; CHECK-LABEL: taken:68; CHECK-NEXT: ret i1 true69  ret i1 %cnd70 71untaken:72; CHECK-LABEL: untaken:73; CHECK-NEXT: ret i1 false74  ret i1 %cnd75}76 77; Not legal to replace use given it's not dominated by edge78define i1 @test2_neg1(ptr %p) {79; CHECK-LABEL: @test2_neg180entry:81  %cnd1 = icmp eq ptr %p, null82  br i1 %cnd1, label %taken, label %untaken83 84taken:85  br label %merge86 87untaken:88  br label %merge89 90merge:91; CHECK-LABEL: merge:92; CHECK-NEXT: ret i1 %cnd193  ret i1 %cnd194}95 96; Another single predecessor test, but for dominated use97define i1 @test2_neg2(ptr %p) {98; CHECK-LABEL: @test2_neg299entry:100  %cnd1 = icmp eq ptr %p, null101  br i1 %cnd1, label %merge, label %merge102 103merge:104; CHECK-LABEL: merge:105; CHECK-NEXT: ret i1 %cnd1106  ret i1 %cnd1107}108 109