[llvm] 4cc9c6d - [VectorCombine] foldShuffleOfBinops - don't fold shuffle(divrem(x,y),divrem(z,w)) if mask contains poison
Simon Pilgrim via llvm-commits
llvm-commits at lists.llvm.org
Mon Apr 22 01:01:09 PDT 2024
Author: Simon Pilgrim
Date: 2024-04-22T09:00:38+01:00
New Revision: 4cc9c6d98dfef90d1ffa69977d13ffa2894a10f7
URL: https://github.com/llvm/llvm-project/commit/4cc9c6d98dfef90d1ffa69977d13ffa2894a10f7
DIFF: https://github.com/llvm/llvm-project/commit/4cc9c6d98dfef90d1ffa69977d13ffa2894a10f7.diff
LOG: [VectorCombine] foldShuffleOfBinops - don't fold shuffle(divrem(x,y),divrem(z,w)) if mask contains poison
Fixes #89390
Added:
Modified:
llvm/lib/Transforms/Vectorize/VectorCombine.cpp
llvm/test/Transforms/VectorCombine/X86/shuffle-of-binops.ll
Removed:
################################################################################
diff --git a/llvm/lib/Transforms/Vectorize/VectorCombine.cpp b/llvm/lib/Transforms/Vectorize/VectorCombine.cpp
index 4918cee1fa82a3..f23b10540338dd 100644
--- a/llvm/lib/Transforms/Vectorize/VectorCombine.cpp
+++ b/llvm/lib/Transforms/Vectorize/VectorCombine.cpp
@@ -1405,6 +1405,11 @@ bool VectorCombine::foldShuffleOfBinops(Instruction &I) {
B0->getOpcode() != B1->getOpcode() || B0->getType() != VecTy)
return false;
+ // Don't introduce poison into div/rem.
+ if (any_of(Mask, [](int M) { return M == PoisonMaskElem; }) &&
+ B0->isIntDivRem())
+ return false;
+
// Try to replace a binop with a shuffle if the shuffle is not costly.
// The new shuffle will choose from a single, common operand, so it may be
// cheaper than the existing two-operand shuffle.
diff --git a/llvm/test/Transforms/VectorCombine/X86/shuffle-of-binops.ll b/llvm/test/Transforms/VectorCombine/X86/shuffle-of-binops.ll
index 6412d6dbf701a3..5c4ad4f1fcc4e5 100644
--- a/llvm/test/Transforms/VectorCombine/X86/shuffle-of-binops.ll
+++ b/llvm/test/Transforms/VectorCombine/X86/shuffle-of-binops.ll
@@ -200,14 +200,14 @@ define <16 x i16> @shuf_and_v16i16_yy_expensive_shuf(<16 x i16> %x, <16 x i16> %
ret <16 x i16> %r
}
-; TODO: negative test - don't fold shuffle(divrem(x,y),divrem(z,w)) if mask contains poison (PR89390)
+; negative test - don't fold shuffle(divrem(x,y),divrem(z,w)) if mask contains poison (PR89390)
define <4 x i32> @shuf_srem_v4i32_poison(<4 x i32> %a0, <4 x i32> %a1) {
; CHECK-LABEL: define <4 x i32> @shuf_srem_v4i32_poison(
; CHECK-SAME: <4 x i32> [[A0:%.*]], <4 x i32> [[A1:%.*]]) #[[ATTR0]] {
-; CHECK-NEXT: [[TMP1:%.*]] = shufflevector <4 x i32> [[A1]], <4 x i32> <i32 1, i32 1, i32 1, i32 1>, <4 x i32> <i32 0, i32 poison, i32 6, i32 3>
-; CHECK-NEXT: [[TMP2:%.*]] = shufflevector <4 x i32> [[A0]], <4 x i32> poison, <4 x i32> <i32 0, i32 poison, i32 2, i32 3>
-; CHECK-NEXT: [[R:%.*]] = srem <4 x i32> [[TMP1]], [[TMP2]]
+; CHECK-NEXT: [[SREM0:%.*]] = srem <4 x i32> [[A1]], [[A0]]
+; CHECK-NEXT: [[SREM1:%.*]] = srem <4 x i32> <i32 1, i32 1, i32 1, i32 1>, [[A0]]
+; CHECK-NEXT: [[R:%.*]] = shufflevector <4 x i32> [[SREM0]], <4 x i32> [[SREM1]], <4 x i32> <i32 0, i32 poison, i32 6, i32 3>
; CHECK-NEXT: ret <4 x i32> [[R]]
;
%srem0 = srem <4 x i32> %a1, %a0
More information about the llvm-commits
mailing list