Skip to content

Commit 853d212

Browse files
committed
[InstSimplify] Update to handle new shufflevector semantics
Simplifying poison mask elements yields poison values. Differential Revision: https://reviews.llvm.org/D149544
1 parent 6f29d1a commit 853d212

File tree

3 files changed

+11
-11
lines changed

3 files changed

+11
-11
lines changed

llvm/lib/Analysis/InstructionSimplify.cpp

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -5236,7 +5236,7 @@ static Value *simplifyShuffleVectorInst(Value *Op0, Value *Op1,
52365236
const SimplifyQuery &Q,
52375237
unsigned MaxRecurse) {
52385238
if (all_of(Mask, [](int Elem) { return Elem == PoisonMaskElem; }))
5239-
return UndefValue::get(RetTy);
5239+
return PoisonValue::get(RetTy);
52405240

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

5304-
// Shuffle mask undefs become undefined constant result elements.
5304+
// Shuffle mask poisons become poison constant result elements.
53055305
SmallVector<Constant *, 16> VecC(MaskNumElts, C);
53065306
for (unsigned i = 0; i != MaskNumElts; ++i)
53075307
if (Indices[i] == -1)
5308-
VecC[i] = UndefValue::get(C->getType());
5308+
VecC[i] = PoisonValue::get(C->getType());
53095309
return ConstantVector::get(VecC);
53105310
}
53115311
}

llvm/test/Transforms/InstSimplify/shufflevector-inseltpoison.ll

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -122,15 +122,15 @@ define <4 x i32> @splat_operand_negative4(<4 x i32> %x) {
122122

123123
define <4 x i32> @undef_mask(<4 x i32> %x) {
124124
; CHECK-LABEL: @undef_mask(
125-
; CHECK-NEXT: ret <4 x i32> undef
125+
; CHECK-NEXT: ret <4 x i32> poison
126126
;
127127
%shuf = shufflevector <4 x i32> %x, <4 x i32> undef, <4 x i32> poison
128128
ret <4 x i32> %shuf
129129
}
130130

131131
define <4 x i32> @undef_mask_1(<4 x i32> %x, <4 x i32> %y) {
132132
; CHECK-LABEL: @undef_mask_1(
133-
; CHECK-NEXT: ret <4 x i32> undef
133+
; CHECK-NEXT: ret <4 x i32> poison
134134
;
135135
%shuf = shufflevector <4 x i32> %x, <4 x i32> %y, <4 x i32> poison
136136
ret <4 x i32> %shuf
@@ -269,7 +269,7 @@ define <5 x i8> @splat_inserted_constant(<4 x i8> %x) {
269269

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

279279
define <2 x i8> @splat_inserted_constant_not_canonical(<3 x i8> %x, <3 x i8> %y) {
280280
; CHECK-LABEL: @splat_inserted_constant_not_canonical(
281-
; CHECK-NEXT: ret <2 x i8> <i8 undef, i8 23>
281+
; CHECK-NEXT: ret <2 x i8> <i8 poison, i8 23>
282282
;
283283
%ins2 = insertelement <3 x i8> %x, i8 23, i7 2
284284
%splat2 = shufflevector <3 x i8> %y, <3 x i8> %ins2, <2 x i32> <i32 undef, i32 5>

llvm/test/Transforms/InstSimplify/shufflevector.ll

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -122,15 +122,15 @@ define <4 x i32> @splat_operand_negative4(<4 x i32> %x) {
122122

123123
define <4 x i32> @undef_mask(<4 x i32> %x) {
124124
; CHECK-LABEL: @undef_mask(
125-
; CHECK-NEXT: ret <4 x i32> undef
125+
; CHECK-NEXT: ret <4 x i32> poison
126126
;
127127
%shuf = shufflevector <4 x i32> %x, <4 x i32> undef, <4 x i32> undef
128128
ret <4 x i32> %shuf
129129
}
130130

131131
define <4 x i32> @undef_mask_1(<4 x i32> %x, <4 x i32> %y) {
132132
; CHECK-LABEL: @undef_mask_1(
133-
; CHECK-NEXT: ret <4 x i32> undef
133+
; CHECK-NEXT: ret <4 x i32> poison
134134
;
135135
%shuf = shufflevector <4 x i32> %x, <4 x i32> %y, <4 x i32> undef
136136
ret <4 x i32> %shuf
@@ -269,7 +269,7 @@ define <5 x i8> @splat_inserted_constant(<4 x i8> %x) {
269269

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

279279
define <2 x i8> @splat_inserted_constant_not_canonical(<3 x i8> %x, <3 x i8> %y) {
280280
; CHECK-LABEL: @splat_inserted_constant_not_canonical(
281-
; CHECK-NEXT: ret <2 x i8> <i8 undef, i8 23>
281+
; CHECK-NEXT: ret <2 x i8> <i8 poison, i8 23>
282282
;
283283
%ins2 = insertelement <3 x i8> %x, i8 23, i7 2
284284
%splat2 = shufflevector <3 x i8> %y, <3 x i8> %ins2, <2 x i32> <i32 undef, i32 5>

0 commit comments

Comments
 (0)