Skip to content

Commit

Permalink
[InstCombineVectorOps] Use poison instead of undef as placeholder [NFC]
Browse files Browse the repository at this point in the history
It's used to create a vector where only 1 element is used
While at it, change OOB extractelement to yield poison per LangRef
  • Loading branch information
nunoplopes committed Jul 29, 2023
1 parent 1a54671 commit eb1617a
Show file tree
Hide file tree
Showing 4 changed files with 12 additions and 12 deletions.
8 changes: 4 additions & 4 deletions llvm/lib/Transforms/InstCombine/InstCombineVectorOps.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -441,7 +441,7 @@ Instruction *InstCombinerImpl::visitExtractElementInst(ExtractElementInst &EI) {
if (IndexC->getValue().getActiveBits() <= BitWidth)
Idx = ConstantInt::get(Ty, IndexC->getValue().zextOrTrunc(BitWidth));
else
Idx = UndefValue::get(Ty);
Idx = PoisonValue::get(Ty);
return replaceInstUsesWith(EI, Idx);
}
}
Expand Down Expand Up @@ -2197,9 +2197,9 @@ static Instruction *canonicalizeInsertSplat(ShuffleVectorInst &Shuf,
!match(Op1, m_Undef()) || match(Mask, m_ZeroMask()) || IndexC == 0)
return nullptr;

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

// Splat from element 0. Any mask element that is undefined remains undefined.
// For example:
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -427,7 +427,7 @@ define <5 x float> @insert_not_undef_shuffle_translate_commute_lengthen(float %x

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

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

define <5 x i7> @insert_nonzero_index_splat_widen(i7 %x) {
; CHECK-LABEL: @insert_nonzero_index_splat_widen(
; CHECK-NEXT: [[TMP1:%.*]] = insertelement <5 x i7> undef, i7 [[X:%.*]], i64 0
; CHECK-NEXT: [[TMP1:%.*]] = insertelement <5 x i7> poison, i7 [[X:%.*]], i64 0
; 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>
; CHECK-NEXT: ret <5 x i7> [[SPLAT]]
;
Expand Down
6 changes: 3 additions & 3 deletions llvm/test/Transforms/InstCombine/insert-extract-shuffle.ll
Original file line number Diff line number Diff line change
Expand Up @@ -427,7 +427,7 @@ define <5 x float> @insert_not_undef_shuffle_translate_commute_lengthen(float %x

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

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

define <5 x i7> @insert_nonzero_index_splat_widen(i7 %x) {
; CHECK-LABEL: @insert_nonzero_index_splat_widen(
; CHECK-NEXT: [[TMP1:%.*]] = insertelement <5 x i7> undef, i7 [[X:%.*]], i64 0
; CHECK-NEXT: [[TMP1:%.*]] = insertelement <5 x i7> poison, i7 [[X:%.*]], i64 0
; 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>
; CHECK-NEXT: ret <5 x i7> [[SPLAT]]
;
Expand Down
4 changes: 2 additions & 2 deletions llvm/test/Transforms/InstCombine/vscale_extractelement.ll
Original file line number Diff line number Diff line change
Expand Up @@ -217,12 +217,12 @@ entry:
ret i64 %1
}

; Check that undef is returned when the extracted element has wrapped.
; Check that poison is returned when the extracted element has wrapped.

define i8 @ext_lane256_from_stepvec() {
; CHECK-LABEL: @ext_lane256_from_stepvec(
; CHECK-NEXT: entry:
; CHECK-NEXT: ret i8 undef
; CHECK-NEXT: ret i8 poison
;
entry:
%0 = call <vscale x 512 x i8> @llvm.experimental.stepvector.nxv512i8()
Expand Down

0 comments on commit eb1617a

Please sign in to comment.