[InstSimplify] fold 'xor X, poison' and 'div/rem X, poison' to poison

This commit is contained in:
Nuno Lopes 2022-01-30 10:46:54 +00:00
parent 42a761e57c
commit 0dc20e321c
2 changed files with 7 additions and 5 deletions

View File

@ -951,7 +951,7 @@ static Value *simplifyDivRem(Instruction::BinaryOps Opcode, Value *Op0,
// X / undef -> poison // X / undef -> poison
// X % undef -> poison // X % undef -> poison
if (Q.isUndefValue(Op1)) if (Q.isUndefValue(Op1) || isa<PoisonValue>(Op1))
return PoisonValue::get(Ty); return PoisonValue::get(Ty);
// X / 0 -> poison // X / 0 -> poison
@ -2418,6 +2418,10 @@ static Value *SimplifyXorInst(Value *Op0, Value *Op1, const SimplifyQuery &Q,
if (Constant *C = foldOrCommuteConstant(Instruction::Xor, Op0, Op1, Q)) if (Constant *C = foldOrCommuteConstant(Instruction::Xor, Op0, Op1, Q))
return C; return C;
// X ^ poison -> poison
if (isa<PoisonValue>(Op1))
return Op1;
// A ^ undef -> undef // A ^ undef -> undef
if (Q.isUndefValue(Op1)) if (Q.isUndefValue(Op1))
return Op1; return Op1;

View File

@ -44,8 +44,7 @@ define i8 @simplify_add_poison(i8 %x) {
define i8 @simplify_xor_poison(i8 %x) { define i8 @simplify_xor_poison(i8 %x) {
; CHECK-LABEL: @simplify_xor_poison( ; CHECK-LABEL: @simplify_xor_poison(
; CHECK-NEXT: [[R:%.*]] = xor i8 poison, [[X:%.*]] ; CHECK-NEXT: ret i8 poison
; CHECK-NEXT: ret i8 [[R]]
; ;
%r = xor i8 poison, %x %r = xor i8 poison, %x
ret i8 %r ret i8 %r
@ -61,8 +60,7 @@ define i8 @simplify_sdiv_poison(i8 %x) {
define i8 @simplify_urem_poison(i8 %x) { define i8 @simplify_urem_poison(i8 %x) {
; CHECK-LABEL: @simplify_urem_poison( ; CHECK-LABEL: @simplify_urem_poison(
; CHECK-NEXT: [[R:%.*]] = urem i8 [[X:%.*]], poison ; CHECK-NEXT: ret i8 poison
; CHECK-NEXT: ret i8 [[R]]
; ;
%r = urem i8 %x, poison %r = urem i8 %x, poison
ret i8 %r ret i8 %r