Skip to content

Commit 01af3d6

Browse files
committed
Exclude div/rem
1 parent ee1e4df commit 01af3d6

File tree

2 files changed

+26
-2
lines changed

2 files changed

+26
-2
lines changed

llvm/lib/Transforms/Vectorize/VectorCombine.cpp

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1762,8 +1762,10 @@ bool VectorCombine::foldShuffleToIdentity(Instruction &I) {
17621762
}))
17631763
return false;
17641764

1765-
// Check the operator is one that we support.
1766-
if (isa<BinaryOperator>(Item[0].first)) {
1765+
// Check the operator is one that we support. We exclude div/rem in case
1766+
// they hit UB from poison lanes.
1767+
if (isa<BinaryOperator>(Item[0].first) &&
1768+
!cast<BinaryOperator>(Item[0].first)->isIntDivRem()) {
17671769
Worklist.push_back(GenerateInstLaneVectorFromOperand(Item, 0));
17681770
Worklist.push_back(GenerateInstLaneVectorFromOperand(Item, 1));
17691771
} else if (isa<UnaryOperator>(Item[0].first)) {

llvm/test/Transforms/VectorCombine/AArch64/shuffletoidentity.ll

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -486,6 +486,28 @@ define <8 x i8> @intrinsics_different(<8 x i8> %a, <8 x i8> %b) {
486486
ret <8 x i8> %r
487487
}
488488

489+
; div and rem are currently excluded.
490+
define <8 x i8> @div(<8 x i8> %a, <8 x i8> %b) {
491+
; CHECK-LABEL: @div(
492+
; CHECK-NEXT: [[AB:%.*]] = shufflevector <8 x i8> [[A:%.*]], <8 x i8> poison, <4 x i32> <i32 3, i32 2, i32 1, i32 0>
493+
; CHECK-NEXT: [[AT:%.*]] = shufflevector <8 x i8> [[A]], <8 x i8> poison, <4 x i32> <i32 7, i32 6, i32 5, i32 4>
494+
; CHECK-NEXT: [[BB:%.*]] = shufflevector <8 x i8> [[B:%.*]], <8 x i8> poison, <4 x i32> <i32 3, i32 2, i32 1, i32 0>
495+
; CHECK-NEXT: [[BT:%.*]] = shufflevector <8 x i8> [[B]], <8 x i8> poison, <4 x i32> <i32 7, i32 6, i32 5, i32 4>
496+
; CHECK-NEXT: [[ABT:%.*]] = udiv <4 x i8> [[AT]], [[BT]]
497+
; CHECK-NEXT: [[ABB:%.*]] = udiv <4 x i8> [[AB]], [[BB]]
498+
; CHECK-NEXT: [[R:%.*]] = shufflevector <4 x i8> [[ABT]], <4 x i8> [[ABB]], <8 x i32> <i32 7, i32 poison, i32 5, i32 4, i32 3, i32 2, i32 1, i32 0>
499+
; CHECK-NEXT: ret <8 x i8> [[R]]
500+
;
501+
%ab = shufflevector <8 x i8> %a, <8 x i8> poison, <4 x i32> <i32 3, i32 2, i32 1, i32 0>
502+
%at = shufflevector <8 x i8> %a, <8 x i8> poison, <4 x i32> <i32 7, i32 6, i32 5, i32 4>
503+
%bb = shufflevector <8 x i8> %b, <8 x i8> poison, <4 x i32> <i32 3, i32 2, i32 1, i32 0>
504+
%bt = shufflevector <8 x i8> %b, <8 x i8> poison, <4 x i32> <i32 7, i32 6, i32 5, i32 4>
505+
%abt = udiv <4 x i8> %at, %bt
506+
%abb = udiv <4 x i8> %ab, %bb
507+
%r = shufflevector <4 x i8> %abt, <4 x i8> %abb, <8 x i32> <i32 7, i32 poison, i32 5, i32 4, i32 3, i32 2, i32 1, i32 0>
508+
ret <8 x i8> %r
509+
}
510+
489511
define void @v8f64interleave(i64 %0, ptr %1, ptr %x, double %z) {
490512
; CHECK-LABEL: @v8f64interleave(
491513
; CHECK-NEXT: entry:

0 commit comments

Comments
 (0)