1
0
mirror of https://github.com/RPCS3/llvm-mirror.git synced 2024-11-22 18:54:02 +01:00

[InstCombine] don't try to fold a constant expression that can trap (PR50906)

We could use a bigger hammer and bail out on any constant
expression, but there's a regression test that appears to
validly do the transform (although it may not have been
intending to check that optimization).
This commit is contained in:
Sanjay Patel 2021-06-28 16:37:10 -04:00
parent 3442700c7c
commit 28df279445
2 changed files with 3 additions and 3 deletions

View File

@ -1440,7 +1440,7 @@ Instruction *InstCombinerImpl::foldICmpWithConstant(ICmpInst &Cmp) {
// icmp(phi(C1, C2, ...), C) -> phi(icmp(C1, C), icmp(C2, C), ...).
Constant *C = dyn_cast<Constant>(Op1);
if (!C)
if (!C || C->canTrap())
return nullptr;
if (auto *Phi = dyn_cast<PHINode>(Op0))

View File

@ -249,7 +249,6 @@ bb10:
ret i1 %cmp
}
; FIXME:
; It is not generally safe to hoist an expression (sdiv) that may trap.
define i1 @PR50906() {
@ -257,9 +256,10 @@ define i1 @PR50906() {
; CHECK-NEXT: entry:
; CHECK-NEXT: br label [[LOOP:%.*]]
; CHECK: loop:
; CHECK-NEXT: [[CMP:%.*]] = phi i1 [ icmp sgt (i32 sdiv (i32 7, i32 ptrtoint (i1 ()* @PR50906 to i32)), i32 1), [[NEXT:%.*]] ], [ icmp sgt (i32 sdiv (i32 7, i32 ptrtoint (i1 ()* @PR50906 to i32)), i32 0), [[ENTRY:%.*]] ]
; CHECK-NEXT: [[PHI:%.*]] = phi i32 [ 0, [[ENTRY:%.*]] ], [ 1, [[NEXT:%.*]] ]
; CHECK-NEXT: br label [[NEXT]]
; CHECK: next:
; CHECK-NEXT: [[CMP:%.*]] = icmp slt i32 [[PHI]], sdiv (i32 7, i32 ptrtoint (i1 ()* @PR50906 to i32))
; CHECK-NEXT: br i1 [[CMP]], label [[EXIT:%.*]], label [[LOOP]]
; CHECK: exit:
; CHECK-NEXT: ret i1 [[CMP]]