From: Florian Hahn Date: Tue, 8 Mar 2022 22:01:53 +0000 (+0000) Subject: [ConstraintElimination] Remove over-eager assertion. X-Git-Tag: upstream/15.0.7~14211 X-Git-Url: http://review.tizen.org/git/?a=commitdiff_plain;h=e10b0ea371a80d059e67b316c082cb1d3b41ec71;p=platform%2Fupstream%2Fllvm.git [ConstraintElimination] Remove over-eager assertion. After moving the CanAdd check in c60cdb44f7ecb4b02ed and using it for the assume cases as well, the passed in block may not have a branch instruction as terminator. This can trigger the assertion. Given the new use case, it doesn't add value any longer and can be removed. Fixes https://github.com/llvm/llvm-project/issues/54281 --- diff --git a/llvm/lib/Transforms/Scalar/ConstraintElimination.cpp b/llvm/lib/Transforms/Scalar/ConstraintElimination.cpp index eb92c11a..f7556bb 100644 --- a/llvm/lib/Transforms/Scalar/ConstraintElimination.cpp +++ b/llvm/lib/Transforms/Scalar/ConstraintElimination.cpp @@ -419,7 +419,6 @@ static bool eliminateConstraints(Function &F, DominatorTree &DT) { // Succ (e.g. the case when adding a condition from a pre-header to a loop // header). auto CanAdd = [&BB, &DT](BasicBlock *Succ) { - assert(isa(BB.getTerminator())); return any_of(successors(&BB), [Succ](const BasicBlock *S) { return S != Succ; }) && all_of(predecessors(Succ), [&BB, &DT, Succ](BasicBlock *Pred) { diff --git a/llvm/test/Transforms/ConstraintElimination/invoke.ll b/llvm/test/Transforms/ConstraintElimination/invoke.ll new file mode 100644 index 0000000..30636bc --- /dev/null +++ b/llvm/test/Transforms/ConstraintElimination/invoke.ll @@ -0,0 +1,50 @@ +; NOTE: Assertions have been autogenerated by utils/update_test_checks.py +; RUN: opt -passes=constraint-elimination -S %s | FileCheck %s + +declare void @may_unwind() + +declare i32 @__gxx_personality_v0(...); + +define i1 @test_invoke_in_block_with_assume(i32 %x) personality i8* bitcast (i32 (...)* @__gxx_personality_v0 to i8*) { +; CHECK-LABEL: @test_invoke_in_block_with_assume( +; CHECK-NEXT: entry: +; CHECK-NEXT: call void @may_unwind() +; CHECK-NEXT: [[C_1:%.*]] = icmp ult i32 [[X:%.*]], 10 +; CHECK-NEXT: call void @llvm.assume(i1 [[C_1]]) +; CHECK-NEXT: invoke void @may_unwind() +; CHECK-NEXT: to label [[CONT:%.*]] unwind label [[LPAD:%.*]] +; CHECK: cont: +; CHECK-NEXT: [[T_1:%.*]] = icmp ult i32 [[X]], 10 +; CHECK-NEXT: [[C_2:%.*]] = icmp ult i32 [[X]], 9 +; CHECK-NEXT: [[RES_1:%.*]] = xor i1 true, [[C_2]] +; CHECK-NEXT: ret i1 [[RES_1]] +; CHECK: lpad: +; CHECK-NEXT: [[LP:%.*]] = landingpad { i8*, i32 } +; CHECK-NEXT: filter [0 x i8*] zeroinitializer +; CHECK-NEXT: [[T_2:%.*]] = icmp ult i32 [[X]], 10 +; CHECK-NEXT: [[C_3:%.*]] = icmp ult i32 [[X]], 9 +; CHECK-NEXT: [[RES_2:%.*]] = xor i1 true, [[C_3]] +; CHECK-NEXT: ret i1 [[RES_2]] +; +entry: + call void @may_unwind() + %c.1 = icmp ult i32 %x, 10 + call void @llvm.assume(i1 %c.1) + invoke void @may_unwind() to label %cont unwind label %lpad + +cont: + %t.1 = icmp ult i32 %x, 10 + %c.2 = icmp ult i32 %x, 9 + %res.1 = xor i1 %t.1, %c.2 + ret i1 %res.1 + +lpad: + %lp = landingpad { i8*, i32 } + filter [0 x i8*] zeroinitializer + %t.2 = icmp ult i32 %x, 10 + %c.3 = icmp ult i32 %x, 9 + %res.2 = xor i1 %t.2, %c.3 + ret i1 %res.2 +} + +declare void @llvm.assume(i1) diff --git a/llvm/test/Transforms/ConstraintElimination/switch.ll b/llvm/test/Transforms/ConstraintElimination/switch.ll new file mode 100644 index 0000000..632a0ba --- /dev/null +++ b/llvm/test/Transforms/ConstraintElimination/switch.ll @@ -0,0 +1,47 @@ +; NOTE: Assertions have been autogenerated by utils/update_test_checks.py +; RUN: opt -passes=constraint-elimination -S %s | FileCheck %s + +declare void @may_unwind() + +define i1 @test_switch_in_block_with_assume(i32 %x) { +; CHECK-LABEL: @test_switch_in_block_with_assume( +; CHECK-NEXT: entry: +; CHECK-NEXT: call void @may_unwind() +; CHECK-NEXT: [[C_1:%.*]] = icmp ult i32 [[X:%.*]], 10 +; CHECK-NEXT: call void @llvm.assume(i1 [[C_1]]) +; CHECK-NEXT: switch i32 0, label [[EXIT_1:%.*]] [ +; CHECK-NEXT: i32 1, label [[EXIT_2:%.*]] +; CHECK-NEXT: ] +; CHECK: exit.1: +; CHECK-NEXT: [[T_1:%.*]] = icmp ult i32 [[X]], 10 +; CHECK-NEXT: [[C_2:%.*]] = icmp ult i32 [[X]], 9 +; CHECK-NEXT: [[RES_1:%.*]] = xor i1 true, [[C_2]] +; CHECK-NEXT: ret i1 [[RES_1]] +; CHECK: exit.2: +; CHECK-NEXT: [[T_2:%.*]] = icmp ult i32 [[X]], 10 +; CHECK-NEXT: [[C_3:%.*]] = icmp ult i32 [[X]], 9 +; CHECK-NEXT: [[RES_2:%.*]] = xor i1 true, [[C_3]] +; CHECK-NEXT: ret i1 [[RES_2]] +; +entry: + call void @may_unwind() + %c.1 = icmp ult i32 %x, 10 + call void @llvm.assume(i1 %c.1) + switch i32 0, label %exit.1 [ + i32 1, label %exit.2 + ] + +exit.1: + %t.1 = icmp ult i32 %x, 10 + %c.2 = icmp ult i32 %x, 9 + %res.1 = xor i1 %t.1, %c.2 + ret i1 %res.1 + +exit.2: + %t.2 = icmp ult i32 %x, 10 + %c.3 = icmp ult i32 %x, 9 + %res.2 = xor i1 %t.2, %c.3 + ret i1 %res.2 +} + +declare void @llvm.assume(i1)