[llvm] 0dc20e3 - [InstSimplify] fold 'xor X, poison' and 'div/rem X, poison' to poison
Nuno Lopes via llvm-commits
llvm-commits at lists.llvm.org
Sun Jan 30 03:04:20 PST 2022
Author: Nuno Lopes
Date: 2022-01-30T10:46:54Z
New Revision: 0dc20e321cb58946cf14e59aa028ab6287bfe687
URL: https://github.com/llvm/llvm-project/commit/0dc20e321cb58946cf14e59aa028ab6287bfe687
DIFF: https://github.com/llvm/llvm-project/commit/0dc20e321cb58946cf14e59aa028ab6287bfe687.diff
LOG: [InstSimplify] fold 'xor X, poison' and 'div/rem X, poison' to poison
Added:
Modified:
llvm/lib/Analysis/InstructionSimplify.cpp
llvm/test/Transforms/NewGVN/basic.ll
Removed:
################################################################################
diff --git a/llvm/lib/Analysis/InstructionSimplify.cpp b/llvm/lib/Analysis/InstructionSimplify.cpp
index b71b39334ace7..4775340b34386 100644
--- a/llvm/lib/Analysis/InstructionSimplify.cpp
+++ b/llvm/lib/Analysis/InstructionSimplify.cpp
@@ -951,7 +951,7 @@ static Value *simplifyDivRem(Instruction::BinaryOps Opcode, Value *Op0,
// X / undef -> poison
// X % undef -> poison
- if (Q.isUndefValue(Op1))
+ if (Q.isUndefValue(Op1) || isa<PoisonValue>(Op1))
return PoisonValue::get(Ty);
// 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))
return C;
+ // X ^ poison -> poison
+ if (isa<PoisonValue>(Op1))
+ return Op1;
+
// A ^ undef -> undef
if (Q.isUndefValue(Op1))
return Op1;
diff --git a/llvm/test/Transforms/NewGVN/basic.ll b/llvm/test/Transforms/NewGVN/basic.ll
index fb167ebd0fac5..970ec81d00544 100644
--- a/llvm/test/Transforms/NewGVN/basic.ll
+++ b/llvm/test/Transforms/NewGVN/basic.ll
@@ -44,8 +44,7 @@ define i8 @simplify_add_poison(i8 %x) {
define i8 @simplify_xor_poison(i8 %x) {
; CHECK-LABEL: @simplify_xor_poison(
-; CHECK-NEXT: [[R:%.*]] = xor i8 poison, [[X:%.*]]
-; CHECK-NEXT: ret i8 [[R]]
+; CHECK-NEXT: ret i8 poison
;
%r = xor i8 poison, %x
ret i8 %r
@@ -61,8 +60,7 @@ define i8 @simplify_sdiv_poison(i8 %x) {
define i8 @simplify_urem_poison(i8 %x) {
; CHECK-LABEL: @simplify_urem_poison(
-; CHECK-NEXT: [[R:%.*]] = urem i8 [[X:%.*]], poison
-; CHECK-NEXT: ret i8 [[R]]
+; CHECK-NEXT: ret i8 poison
;
%r = urem i8 %x, poison
ret i8 %r
More information about the llvm-commits
mailing list