Skip to content

Commit 4cc9c6d

Browse files
committed
[VectorCombine] foldShuffleOfBinops - don't fold shuffle(divrem(x,y),divrem(z,w)) if mask contains poison
Fixes #89390
1 parent 3fbaad5 commit 4cc9c6d

File tree

2 files changed

+9
-4
lines changed

2 files changed

+9
-4
lines changed

llvm/lib/Transforms/Vectorize/VectorCombine.cpp

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1405,6 +1405,11 @@ bool VectorCombine::foldShuffleOfBinops(Instruction &I) {
14051405
B0->getOpcode() != B1->getOpcode() || B0->getType() != VecTy)
14061406
return false;
14071407

1408+
// Don't introduce poison into div/rem.
1409+
if (any_of(Mask, [](int M) { return M == PoisonMaskElem; }) &&
1410+
B0->isIntDivRem())
1411+
return false;
1412+
14081413
// Try to replace a binop with a shuffle if the shuffle is not costly.
14091414
// The new shuffle will choose from a single, common operand, so it may be
14101415
// cheaper than the existing two-operand shuffle.

llvm/test/Transforms/VectorCombine/X86/shuffle-of-binops.ll

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -200,14 +200,14 @@ define <16 x i16> @shuf_and_v16i16_yy_expensive_shuf(<16 x i16> %x, <16 x i16> %
200200
ret <16 x i16> %r
201201
}
202202

203-
; TODO: negative test - don't fold shuffle(divrem(x,y),divrem(z,w)) if mask contains poison (PR89390)
203+
; negative test - don't fold shuffle(divrem(x,y),divrem(z,w)) if mask contains poison (PR89390)
204204

205205
define <4 x i32> @shuf_srem_v4i32_poison(<4 x i32> %a0, <4 x i32> %a1) {
206206
; CHECK-LABEL: define <4 x i32> @shuf_srem_v4i32_poison(
207207
; CHECK-SAME: <4 x i32> [[A0:%.*]], <4 x i32> [[A1:%.*]]) #[[ATTR0]] {
208-
; 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>
209-
; CHECK-NEXT: [[TMP2:%.*]] = shufflevector <4 x i32> [[A0]], <4 x i32> poison, <4 x i32> <i32 0, i32 poison, i32 2, i32 3>
210-
; CHECK-NEXT: [[R:%.*]] = srem <4 x i32> [[TMP1]], [[TMP2]]
208+
; CHECK-NEXT: [[SREM0:%.*]] = srem <4 x i32> [[A1]], [[A0]]
209+
; CHECK-NEXT: [[SREM1:%.*]] = srem <4 x i32> <i32 1, i32 1, i32 1, i32 1>, [[A0]]
210+
; CHECK-NEXT: [[R:%.*]] = shufflevector <4 x i32> [[SREM0]], <4 x i32> [[SREM1]], <4 x i32> <i32 0, i32 poison, i32 6, i32 3>
211211
; CHECK-NEXT: ret <4 x i32> [[R]]
212212
;
213213
%srem0 = srem <4 x i32> %a1, %a0

0 commit comments

Comments
 (0)