70 lines · plain
1; RUN: opt -S -passes=jump-threading %s | FileCheck %s2; When simplify a branch based on LVI predicates, we should replace the3; comparison itself with a constant (when possible) in case it's otherwise used.4 5define i32 @test(ptr %p) {6; CHECK-LABEL: @test7; CHECK: icmp eq8; CHECK-NEXT: br i1 %cmp, label %exit2, label %exit19; CHECK-NOT: icmp ne10entry:11 %cmp = icmp eq ptr %p, null12 br i1 %cmp, label %is_null, label %not_null13is_null:14 %cmp2 = icmp ne ptr %p, null15 br i1 %cmp2, label %exit1, label %exit216not_null:17 %cmp3 = icmp ne ptr %p, null18 br i1 %cmp3, label %exit1, label %exit219exit1:20 ret i32 021exit2:22 ret i32 123}24 25declare void @use(i1)26 27; It would not be legal to replace %cmp2 (well, in this case it actually is,28; but that's a CSE problem, not a LVI/jump threading problem)29define i32 @test_negative(ptr %p) {30; CHECK-LABEL: @test31; CHECK: icmp ne32; CHECK: icmp eq33; CHECK-NEXT: br i1 %cmp, label %exit2, label %exit134; CHECK-NOT: icmp ne35entry:36 %cmp2 = icmp ne ptr %p, null37 call void @use(i1 %cmp2)38 %cmp = icmp eq ptr %p, null39 br i1 %cmp, label %is_null, label %not_null40is_null:41 br i1 %cmp2, label %exit1, label %exit242not_null:43 br i1 %cmp2, label %exit1, label %exit244exit1:45 ret i32 046exit2:47 ret i32 148}49 50; In this case, we can remove cmp2 because it's otherwise unused51define i32 @test2(ptr %p) {52; CHECK-LABEL: @test53; CHECK-LABEL: entry:54; CHECK-NEXT: icmp eq55; CHECK-NEXT: br i1 %cmp, label %exit2, label %exit156; CHECK-NOT: icmp ne57entry:58 %cmp2 = icmp ne ptr %p, null59 %cmp = icmp eq ptr %p, null60 br i1 %cmp, label %is_null, label %not_null61is_null:62 br i1 %cmp2, label %exit1, label %exit263not_null:64 br i1 %cmp2, label %exit1, label %exit265exit1:66 ret i32 067exit2:68 ret i32 169}70