forked from OSchip/llvm-project
[InstCombine] Matchers work with both ConstExpr and Instructions.
So, `cast<Instruction>` is not guaranteed to succeed. Change the code so that we create a new constant and use it in the newly created instruction, as it's done in other places in InstCombine. OK'ed by Sanjay/Craig. Fixes PR32686. llvm-svn: 300495
This commit is contained in:
parent
8c4053372e
commit
cdc937d0fc
|
@ -2078,7 +2078,7 @@ Instruction *InstCombiner::visitOr(BinaryOperator &I) {
|
||||||
Value *NOr = Builder->CreateOr(A, Op1);
|
Value *NOr = Builder->CreateOr(A, Op1);
|
||||||
NOr->takeName(Op0);
|
NOr->takeName(Op0);
|
||||||
return BinaryOperator::CreateXor(NOr,
|
return BinaryOperator::CreateXor(NOr,
|
||||||
cast<Instruction>(Op0)->getOperand(1));
|
ConstantInt::get(NOr->getType(), *C));
|
||||||
}
|
}
|
||||||
|
|
||||||
// Y|(X^C) -> (X|Y)^C iff Y&C == 0
|
// Y|(X^C) -> (X|Y)^C iff Y&C == 0
|
||||||
|
@ -2087,7 +2087,7 @@ Instruction *InstCombiner::visitOr(BinaryOperator &I) {
|
||||||
Value *NOr = Builder->CreateOr(A, Op0);
|
Value *NOr = Builder->CreateOr(A, Op0);
|
||||||
NOr->takeName(Op0);
|
NOr->takeName(Op0);
|
||||||
return BinaryOperator::CreateXor(NOr,
|
return BinaryOperator::CreateXor(NOr,
|
||||||
cast<Instruction>(Op1)->getOperand(1));
|
ConstantInt::get(NOr->getType(), *C));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -0,0 +1,22 @@
|
||||||
|
; RUN: opt -S -instcombine %s | FileCheck %s
|
||||||
|
|
||||||
|
; CHECK-LABEL: define void @tinkywinky
|
||||||
|
; CHECK-NEXT: %patatino = load i8, i8* @a, align 1
|
||||||
|
; CHECK-NEXT: %tobool = icmp eq i8 %patatino, 0
|
||||||
|
; CHECK-NEXT: %1 = zext i1 %tobool to i32
|
||||||
|
; CHECK-NEXT: %or1 = or i32 %1, or (i32 zext (i1 icmp ne (i32* bitcast (i8* @a to i32*), i32* @b) to i32), i32 2)
|
||||||
|
; CHECK-NEXT: store i32 %or1, i32* @b, align 4
|
||||||
|
; CHECK-NEXT: ret void
|
||||||
|
|
||||||
|
@a = external global i8
|
||||||
|
@b = external global i32
|
||||||
|
|
||||||
|
define void @tinkywinky() {
|
||||||
|
%patatino = load i8, i8* @a
|
||||||
|
%tobool = icmp ne i8 %patatino, 0
|
||||||
|
%lnot = xor i1 %tobool, true
|
||||||
|
%lnot.ext = zext i1 %lnot to i32
|
||||||
|
%or = or i32 xor (i32 zext (i1 icmp ne (i32* bitcast (i8* @a to i32*), i32* @b) to i32), i32 2), %lnot.ext
|
||||||
|
store i32 %or, i32* @b, align 4
|
||||||
|
ret void
|
||||||
|
}
|
Loading…
Reference in New Issue