Skip to content

Commit c31ac81

Browse files
authored
[InstSimplify] Fold (insertelement Splat(C), C, X) -> Splat(C) (#102315)
The index doesn't matter here.
1 parent 06a808c commit c31ac81

File tree

2 files changed

+12
-0
lines changed

2 files changed

+12
-0
lines changed

llvm/lib/Analysis/InstructionSimplify.cpp

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5181,6 +5181,10 @@ Value *llvm::simplifyInsertElementInst(Value *Vec, Value *Val, Value *Idx,
51815181
(Q.isUndefValue(Val) && isGuaranteedNotToBePoison(Vec)))
51825182
return Vec;
51835183

5184+
// Inserting the splatted value into a constant splat does nothing.
5185+
if (VecC && ValC && VecC->getSplatValue() == ValC)
5186+
return Vec;
5187+
51845188
// If we are extracting a value from a vector, then inserting it into the same
51855189
// place, that's the input vector:
51865190
// insertelt Vec, (extractelt Vec, Idx), Idx --> Vec

llvm/test/Transforms/InstSimplify/insertelement.ll

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -119,3 +119,11 @@ unreachable_infloop:
119119
%bogus = insertelement <2 x i64> %bogus, i64 undef, i32 1
120120
br label %unreachable_infloop
121121
}
122+
123+
define <4 x i32> @insert_into_splat(i32 %index) {
124+
; CHECK-LABEL: @insert_into_splat(
125+
; CHECK-NEXT: ret <4 x i32> <i32 3, i32 3, i32 3, i32 3>
126+
;
127+
%I = insertelement <4 x i32> <i32 3, i32 3, i32 3, i32 3>, i32 3, i32 %index
128+
ret <4 x i32> %I
129+
}

0 commit comments

Comments
 (0)