1
0
mirror of https://github.com/RPCS3/llvm-mirror.git synced 2024-10-19 11:02:59 +02:00

[InstSimplify] Handle not inserted instruction gracefully (PR46638)

When simplifying comparisons using a dominating assume, bail out
if the context instruction is not inserted.
This commit is contained in:
Nikita Popov 2020-07-08 21:29:43 +02:00
parent 093cab7840
commit b94ca47521
2 changed files with 47 additions and 1 deletions

View File

@ -3284,7 +3284,8 @@ static Value *simplifyICmpWithMinMax(CmpInst::Predicate Pred, Value *LHS,
static Value *simplifyICmpWithDominatingAssume(CmpInst::Predicate Predicate,
Value *LHS, Value *RHS,
const SimplifyQuery &Q) {
if (!Q.AC || !Q.CxtI)
// Gracefully handle instructions that have not been inserted yet.
if (!Q.AC || !Q.CxtI || !Q.CxtI->getParent())
return nullptr;
for (Value *AssumeBaseOp : {LHS, RHS}) {

View File

@ -0,0 +1,45 @@
; NOTE: Assertions have been autogenerated by utils/update_test_checks.py
; RUN: opt -S -simplifycfg < %s | FileCheck %s
define void @pr46638(i1 %c, i32 %x) {
; CHECK-LABEL: @pr46638(
; CHECK-NEXT: [[CMP1:%.*]] = icmp slt i32 [[X:%.*]], 0
; CHECK-NEXT: call void @llvm.assume(i1 [[CMP1]])
; CHECK-NEXT: br i1 [[C:%.*]], label [[TRUE2_CRITEDGE:%.*]], label [[FALSE1:%.*]]
; CHECK: false1:
; CHECK-NEXT: call void @dummy(i32 1)
; CHECK-NEXT: [[CMP2:%.*]] = icmp sgt i32 [[X]], 0
; CHECK-NEXT: [[EXT:%.*]] = zext i1 [[CMP2]] to i32
; CHECK-NEXT: call void @dummy(i32 [[EXT]])
; CHECK-NEXT: ret void
; CHECK: true2.critedge:
; CHECK-NEXT: [[CMP2_C:%.*]] = icmp sgt i32 [[X]], 0
; CHECK-NEXT: [[EXT_C:%.*]] = zext i1 [[CMP2_C]] to i32
; CHECK-NEXT: call void @dummy(i32 [[EXT_C]])
; CHECK-NEXT: call void @dummy(i32 2)
; CHECK-NEXT: ret void
;
%cmp1 = icmp slt i32 %x, 0
call void @llvm.assume(i1 %cmp1)
br i1 %c, label %true1, label %false1
true1:
%cmp2 = icmp sgt i32 %x, 0
%ext = zext i1 %cmp2 to i32
call void @dummy(i32 %ext)
br i1 %c, label %true2, label %false2
false1:
call void @dummy(i32 1)
br label %true1
true2:
call void @dummy(i32 2)
ret void
false2:
ret void
}
declare void @dummy(i32)
declare void @llvm.assume(i1)