Skip to content

Commit 92fc4b4

Browse files
committed
[InstCombine] Preserve poison in bitcast of insertelement fold
If the base was poison, retain the poison value.
1 parent ddb6db4 commit 92fc4b4

File tree

2 files changed

+5
-4
lines changed

2 files changed

+5
-4
lines changed

llvm/lib/Transforms/InstCombine/InstCombineVectorOps.cpp

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1633,7 +1633,8 @@ Instruction *InstCombinerImpl::visitInsertElementInst(InsertElementInst &IE) {
16331633
// bitcast (inselt undef, ScalarSrc, IdxOp)
16341634
Type *ScalarTy = ScalarSrc->getType();
16351635
Type *VecTy = VectorType::get(ScalarTy, IE.getType()->getElementCount());
1636-
UndefValue *NewUndef = UndefValue::get(VecTy);
1636+
Constant *NewUndef = isa<PoisonValue>(VecOp) ? PoisonValue::get(VecTy)
1637+
: UndefValue::get(VecTy);
16371638
Value *NewInsElt = Builder.CreateInsertElement(NewUndef, ScalarSrc, IdxOp);
16381639
return new BitCastInst(NewInsElt, IE.getType());
16391640
}

llvm/test/Transforms/InstCombine/bitcast-vec-canon-inseltpoison.ll

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -74,7 +74,7 @@ entry:
7474

7575
define <3 x i64> @bitcast_inselt_undef(double %x, i32 %idx) {
7676
; CHECK-LABEL: @bitcast_inselt_undef(
77-
; CHECK-NEXT: [[TMP1:%.*]] = insertelement <3 x double> undef, double [[X:%.*]], i32 [[IDX:%.*]]
77+
; CHECK-NEXT: [[TMP1:%.*]] = insertelement <3 x double> poison, double [[X:%.*]], i32 [[IDX:%.*]]
7878
; CHECK-NEXT: [[I:%.*]] = bitcast <3 x double> [[TMP1]] to <3 x i64>
7979
; CHECK-NEXT: ret <3 x i64> [[I]]
8080
;
@@ -87,7 +87,7 @@ define <3 x i64> @bitcast_inselt_undef(double %x, i32 %idx) {
8787

8888
define <3 x float> @bitcast_inselt_undef_fp(i32 %x, i567 %idx) {
8989
; CHECK-LABEL: @bitcast_inselt_undef_fp(
90-
; CHECK-NEXT: [[TMP1:%.*]] = insertelement <3 x i32> undef, i32 [[X:%.*]], i567 [[IDX:%.*]]
90+
; CHECK-NEXT: [[TMP1:%.*]] = insertelement <3 x i32> poison, i32 [[X:%.*]], i567 [[IDX:%.*]]
9191
; CHECK-NEXT: [[I:%.*]] = bitcast <3 x i32> [[TMP1]] to <3 x float>
9292
; CHECK-NEXT: ret <3 x float> [[I]]
9393
;
@@ -98,7 +98,7 @@ define <3 x float> @bitcast_inselt_undef_fp(i32 %x, i567 %idx) {
9898

9999
define <vscale x 3 x float> @bitcast_inselt_undef_vscale(i32 %x, i567 %idx) {
100100
; CHECK-LABEL: @bitcast_inselt_undef_vscale(
101-
; CHECK-NEXT: [[TMP1:%.*]] = insertelement <vscale x 3 x i32> undef, i32 [[X:%.*]], i567 [[IDX:%.*]]
101+
; CHECK-NEXT: [[TMP1:%.*]] = insertelement <vscale x 3 x i32> poison, i32 [[X:%.*]], i567 [[IDX:%.*]]
102102
; CHECK-NEXT: [[I:%.*]] = bitcast <vscale x 3 x i32> [[TMP1]] to <vscale x 3 x float>
103103
; CHECK-NEXT: ret <vscale x 3 x float> [[I]]
104104
;

0 commit comments

Comments
 (0)