Skip to content

Commit

Permalink
[InstSimplify] Update to handle new shufflevector semantics
Browse files Browse the repository at this point in the history
Simplifying poison mask elements yields poison values.

Differential Revision: https://reviews.llvm.org/D149544
  • Loading branch information
ManuelJBrito committed May 3, 2023
1 parent 6f29d1a commit 853d212
Show file tree
Hide file tree
Showing 3 changed files with 11 additions and 11 deletions.
6 changes: 3 additions & 3 deletions llvm/lib/Analysis/InstructionSimplify.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -5236,7 +5236,7 @@ static Value *simplifyShuffleVectorInst(Value *Op0, Value *Op1,
const SimplifyQuery &Q,
unsigned MaxRecurse) {
if (all_of(Mask, [](int Elem) { return Elem == PoisonMaskElem; }))
return UndefValue::get(RetTy);
return PoisonValue::get(RetTy);

auto *InVecTy = cast<VectorType>(Op0->getType());
unsigned MaskNumElts = Mask.size();
Expand Down Expand Up @@ -5301,11 +5301,11 @@ static Value *simplifyShuffleVectorInst(Value *Op0, Value *Op1,
})) {
assert(isa<UndefValue>(Op1) && "Expected undef operand 1 for splat");

// Shuffle mask undefs become undefined constant result elements.
// Shuffle mask poisons become poison constant result elements.
SmallVector<Constant *, 16> VecC(MaskNumElts, C);
for (unsigned i = 0; i != MaskNumElts; ++i)
if (Indices[i] == -1)
VecC[i] = UndefValue::get(C->getType());
VecC[i] = PoisonValue::get(C->getType());
return ConstantVector::get(VecC);
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -122,15 +122,15 @@ define <4 x i32> @splat_operand_negative4(<4 x i32> %x) {

define <4 x i32> @undef_mask(<4 x i32> %x) {
; CHECK-LABEL: @undef_mask(
; CHECK-NEXT: ret <4 x i32> undef
; CHECK-NEXT: ret <4 x i32> poison
;
%shuf = shufflevector <4 x i32> %x, <4 x i32> undef, <4 x i32> poison
ret <4 x i32> %shuf
}

define <4 x i32> @undef_mask_1(<4 x i32> %x, <4 x i32> %y) {
; CHECK-LABEL: @undef_mask_1(
; CHECK-NEXT: ret <4 x i32> undef
; CHECK-NEXT: ret <4 x i32> poison
;
%shuf = shufflevector <4 x i32> %x, <4 x i32> %y, <4 x i32> poison
ret <4 x i32> %shuf
Expand Down Expand Up @@ -269,7 +269,7 @@ define <5 x i8> @splat_inserted_constant(<4 x i8> %x) {

define <4 x float> @splat_inserted_constant_undef_elt(<4 x float> %x) {
; CHECK-LABEL: @splat_inserted_constant_undef_elt(
; CHECK-NEXT: ret <4 x float> <float 1.200000e+01, float 1.200000e+01, float undef, float 1.200000e+01>
; CHECK-NEXT: ret <4 x float> <float 1.200000e+01, float 1.200000e+01, float poison, float 1.200000e+01>
;
%ins1 = insertelement <4 x float> %x, float 12.0, i32 1
%splat1 = shufflevector <4 x float> %ins1, <4 x float> poison, <4 x i32> <i32 1, i32 1, i32 undef, i32 1>
Expand All @@ -278,7 +278,7 @@ define <4 x float> @splat_inserted_constant_undef_elt(<4 x float> %x) {

define <2 x i8> @splat_inserted_constant_not_canonical(<3 x i8> %x, <3 x i8> %y) {
; CHECK-LABEL: @splat_inserted_constant_not_canonical(
; CHECK-NEXT: ret <2 x i8> <i8 undef, i8 23>
; CHECK-NEXT: ret <2 x i8> <i8 poison, i8 23>
;
%ins2 = insertelement <3 x i8> %x, i8 23, i7 2
%splat2 = shufflevector <3 x i8> %y, <3 x i8> %ins2, <2 x i32> <i32 undef, i32 5>
Expand Down
8 changes: 4 additions & 4 deletions llvm/test/Transforms/InstSimplify/shufflevector.ll
Original file line number Diff line number Diff line change
Expand Up @@ -122,15 +122,15 @@ define <4 x i32> @splat_operand_negative4(<4 x i32> %x) {

define <4 x i32> @undef_mask(<4 x i32> %x) {
; CHECK-LABEL: @undef_mask(
; CHECK-NEXT: ret <4 x i32> undef
; CHECK-NEXT: ret <4 x i32> poison
;
%shuf = shufflevector <4 x i32> %x, <4 x i32> undef, <4 x i32> undef
ret <4 x i32> %shuf
}

define <4 x i32> @undef_mask_1(<4 x i32> %x, <4 x i32> %y) {
; CHECK-LABEL: @undef_mask_1(
; CHECK-NEXT: ret <4 x i32> undef
; CHECK-NEXT: ret <4 x i32> poison
;
%shuf = shufflevector <4 x i32> %x, <4 x i32> %y, <4 x i32> undef
ret <4 x i32> %shuf
Expand Down Expand Up @@ -269,7 +269,7 @@ define <5 x i8> @splat_inserted_constant(<4 x i8> %x) {

define <4 x float> @splat_inserted_constant_undef_elt(<4 x float> %x) {
; CHECK-LABEL: @splat_inserted_constant_undef_elt(
; CHECK-NEXT: ret <4 x float> <float 1.200000e+01, float 1.200000e+01, float undef, float 1.200000e+01>
; CHECK-NEXT: ret <4 x float> <float 1.200000e+01, float 1.200000e+01, float poison, float 1.200000e+01>
;
%ins1 = insertelement <4 x float> %x, float 12.0, i32 1
%splat1 = shufflevector <4 x float> %ins1, <4 x float> undef, <4 x i32> <i32 1, i32 1, i32 undef, i32 1>
Expand All @@ -278,7 +278,7 @@ define <4 x float> @splat_inserted_constant_undef_elt(<4 x float> %x) {

define <2 x i8> @splat_inserted_constant_not_canonical(<3 x i8> %x, <3 x i8> %y) {
; CHECK-LABEL: @splat_inserted_constant_not_canonical(
; CHECK-NEXT: ret <2 x i8> <i8 undef, i8 23>
; CHECK-NEXT: ret <2 x i8> <i8 poison, i8 23>
;
%ins2 = insertelement <3 x i8> %x, i8 23, i7 2
%splat2 = shufflevector <3 x i8> %y, <3 x i8> %ins2, <2 x i32> <i32 undef, i32 5>
Expand Down

0 comments on commit 853d212

Please sign in to comment.