Skip to content

Commit eb1617a

Browse files
committed
[InstCombineVectorOps] Use poison instead of undef as placeholder [NFC]
It's used to create a vector where only 1 element is used While at it, change OOB extractelement to yield poison per LangRef
1 parent 1a54671 commit eb1617a

File tree

4 files changed

+12
-12
lines changed

4 files changed

+12
-12
lines changed

llvm/lib/Transforms/InstCombine/InstCombineVectorOps.cpp

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -441,7 +441,7 @@ Instruction *InstCombinerImpl::visitExtractElementInst(ExtractElementInst &EI) {
441441
if (IndexC->getValue().getActiveBits() <= BitWidth)
442442
Idx = ConstantInt::get(Ty, IndexC->getValue().zextOrTrunc(BitWidth));
443443
else
444-
Idx = UndefValue::get(Ty);
444+
Idx = PoisonValue::get(Ty);
445445
return replaceInstUsesWith(EI, Idx);
446446
}
447447
}
@@ -2197,9 +2197,9 @@ static Instruction *canonicalizeInsertSplat(ShuffleVectorInst &Shuf,
21972197
!match(Op1, m_Undef()) || match(Mask, m_ZeroMask()) || IndexC == 0)
21982198
return nullptr;
21992199

2200-
// Insert into element 0 of an undef vector.
2201-
UndefValue *UndefVec = UndefValue::get(Shuf.getType());
2202-
Value *NewIns = Builder.CreateInsertElement(UndefVec, X, (uint64_t)0);
2200+
// Insert into element 0 of a poison vector.
2201+
PoisonValue *PoisonVec = PoisonValue::get(Shuf.getType());
2202+
Value *NewIns = Builder.CreateInsertElement(PoisonVec, X, (uint64_t)0);
22032203

22042204
// Splat from element 0. Any mask element that is undefined remains undefined.
22052205
// For example:

llvm/test/Transforms/InstCombine/insert-extract-shuffle-inseltpoison.ll

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -427,7 +427,7 @@ define <5 x float> @insert_not_undef_shuffle_translate_commute_lengthen(float %x
427427

428428
define <4 x float> @insert_nonzero_index_splat(float %x) {
429429
; CHECK-LABEL: @insert_nonzero_index_splat(
430-
; CHECK-NEXT: [[TMP1:%.*]] = insertelement <4 x float> undef, float [[X:%.*]], i64 0
430+
; CHECK-NEXT: [[TMP1:%.*]] = insertelement <4 x float> poison, float [[X:%.*]], i64 0
431431
; CHECK-NEXT: [[SPLAT:%.*]] = shufflevector <4 x float> [[TMP1]], <4 x float> poison, <4 x i32> <i32 poison, i32 0, i32 0, i32 poison>
432432
; CHECK-NEXT: ret <4 x float> [[SPLAT]]
433433
;
@@ -438,7 +438,7 @@ define <4 x float> @insert_nonzero_index_splat(float %x) {
438438

439439
define <3 x double> @insert_nonzero_index_splat_narrow(double %x) {
440440
; CHECK-LABEL: @insert_nonzero_index_splat_narrow(
441-
; CHECK-NEXT: [[TMP1:%.*]] = insertelement <3 x double> undef, double [[X:%.*]], i64 0
441+
; CHECK-NEXT: [[TMP1:%.*]] = insertelement <3 x double> poison, double [[X:%.*]], i64 0
442442
; CHECK-NEXT: [[SPLAT:%.*]] = shufflevector <3 x double> [[TMP1]], <3 x double> poison, <3 x i32> <i32 0, i32 poison, i32 0>
443443
; CHECK-NEXT: ret <3 x double> [[SPLAT]]
444444
;
@@ -449,7 +449,7 @@ define <3 x double> @insert_nonzero_index_splat_narrow(double %x) {
449449

450450
define <5 x i7> @insert_nonzero_index_splat_widen(i7 %x) {
451451
; CHECK-LABEL: @insert_nonzero_index_splat_widen(
452-
; CHECK-NEXT: [[TMP1:%.*]] = insertelement <5 x i7> undef, i7 [[X:%.*]], i64 0
452+
; CHECK-NEXT: [[TMP1:%.*]] = insertelement <5 x i7> poison, i7 [[X:%.*]], i64 0
453453
; CHECK-NEXT: [[SPLAT:%.*]] = shufflevector <5 x i7> [[TMP1]], <5 x i7> poison, <5 x i32> <i32 poison, i32 0, i32 0, i32 poison, i32 0>
454454
; CHECK-NEXT: ret <5 x i7> [[SPLAT]]
455455
;

llvm/test/Transforms/InstCombine/insert-extract-shuffle.ll

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -427,7 +427,7 @@ define <5 x float> @insert_not_undef_shuffle_translate_commute_lengthen(float %x
427427

428428
define <4 x float> @insert_nonzero_index_splat(float %x) {
429429
; CHECK-LABEL: @insert_nonzero_index_splat(
430-
; CHECK-NEXT: [[TMP1:%.*]] = insertelement <4 x float> undef, float [[X:%.*]], i64 0
430+
; CHECK-NEXT: [[TMP1:%.*]] = insertelement <4 x float> poison, float [[X:%.*]], i64 0
431431
; CHECK-NEXT: [[SPLAT:%.*]] = shufflevector <4 x float> [[TMP1]], <4 x float> poison, <4 x i32> <i32 poison, i32 0, i32 0, i32 poison>
432432
; CHECK-NEXT: ret <4 x float> [[SPLAT]]
433433
;
@@ -438,7 +438,7 @@ define <4 x float> @insert_nonzero_index_splat(float %x) {
438438

439439
define <3 x double> @insert_nonzero_index_splat_narrow(double %x) {
440440
; CHECK-LABEL: @insert_nonzero_index_splat_narrow(
441-
; CHECK-NEXT: [[TMP1:%.*]] = insertelement <3 x double> undef, double [[X:%.*]], i64 0
441+
; CHECK-NEXT: [[TMP1:%.*]] = insertelement <3 x double> poison, double [[X:%.*]], i64 0
442442
; CHECK-NEXT: [[SPLAT:%.*]] = shufflevector <3 x double> [[TMP1]], <3 x double> poison, <3 x i32> <i32 0, i32 poison, i32 0>
443443
; CHECK-NEXT: ret <3 x double> [[SPLAT]]
444444
;
@@ -449,7 +449,7 @@ define <3 x double> @insert_nonzero_index_splat_narrow(double %x) {
449449

450450
define <5 x i7> @insert_nonzero_index_splat_widen(i7 %x) {
451451
; CHECK-LABEL: @insert_nonzero_index_splat_widen(
452-
; CHECK-NEXT: [[TMP1:%.*]] = insertelement <5 x i7> undef, i7 [[X:%.*]], i64 0
452+
; CHECK-NEXT: [[TMP1:%.*]] = insertelement <5 x i7> poison, i7 [[X:%.*]], i64 0
453453
; CHECK-NEXT: [[SPLAT:%.*]] = shufflevector <5 x i7> [[TMP1]], <5 x i7> poison, <5 x i32> <i32 poison, i32 0, i32 0, i32 poison, i32 0>
454454
; CHECK-NEXT: ret <5 x i7> [[SPLAT]]
455455
;

llvm/test/Transforms/InstCombine/vscale_extractelement.ll

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -217,12 +217,12 @@ entry:
217217
ret i64 %1
218218
}
219219

220-
; Check that undef is returned when the extracted element has wrapped.
220+
; Check that poison is returned when the extracted element has wrapped.
221221

222222
define i8 @ext_lane256_from_stepvec() {
223223
; CHECK-LABEL: @ext_lane256_from_stepvec(
224224
; CHECK-NEXT: entry:
225-
; CHECK-NEXT: ret i8 undef
225+
; CHECK-NEXT: ret i8 poison
226226
;
227227
entry:
228228
%0 = call <vscale x 512 x i8> @llvm.experimental.stepvector.nxv512i8()

0 commit comments

Comments
 (0)