llvm.org GIT mirror llvm / 8dc3a07
[InstSimplify] insertelement V, undef, ? --> V This was part of InstCombine, but it's better placed in InstSimplify. InstCombine also had an unreachable but weaker fold for insertelement with undef index, so that is deleted. git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@361559 91177308-0d34-0410-b5e6-96231b3b80d8 Sanjay Patel 3 months ago
4 changed file(s) with 30 addition(s) and 17 deletion(s). Raw diff Collapse all Expand all
40104010 if (isa(Idx))
40114011 return UndefValue::get(Vec->getType());
40124012
4013 // Inserting an undef scalar? Assume it is the same value as the existing
4014 // vector element.
4015 if (isa(Val))
4016 return Vec;
4017
40134018 return nullptr;
40144019 }
40154020
861861 if (auto *V = SimplifyInsertElementInst(
862862 VecOp, ScalarOp, IdxOp, SQ.getWithInstruction(&IE)))
863863 return replaceInstUsesWith(IE, V);
864
865 // Inserting an undef or into an undefined place, remove this.
866 if (isa(ScalarOp) || isa(IdxOp))
867 replaceInstUsesWith(IE, VecOp);
868864
869865 // If the vector and scalar are both bitcast from the same element type, do
870866 // the insert in that source type followed by bitcast.
+0
-8
test/Transforms/InstCombine/vec_insertelt.ll less more
None ; RUN: opt < %s -instcombine -S | FileCheck %s
1 ; CHECK: ret <4 x i32> %A
2
3 ; PR1286
4 define <4 x i32> @test1(<4 x i32> %A) {
5 %B = insertelement <4 x i32> %A, i32 undef, i32 1
6 ret <4 x i32> %B
7 }
0 ; NOTE: Assertions have been autogenerated by utils/update_test_checks.py
1 ; RUN: opt -S -instsimplify < %s | FileCheck %s
12
23 define <4 x i32> @test1(<4 x i32> %A) {
4 ; CHECK-LABEL: @test1(
5 ; CHECK-NEXT: ret <4 x i32> undef
6 ;
37 %I = insertelement <4 x i32> %A, i32 5, i64 4294967296
4 ; CHECK: ret <4 x i32> undef
58 ret <4 x i32> %I
69 }
710
811 define <4 x i32> @test2(<4 x i32> %A) {
12 ; CHECK-LABEL: @test2(
13 ; CHECK-NEXT: ret <4 x i32> undef
14 ;
915 %I = insertelement <4 x i32> %A, i32 5, i64 4
10 ; CHECK: ret <4 x i32> undef
1116 ret <4 x i32> %I
1217 }
1318
1419 define <4 x i32> @test3(<4 x i32> %A) {
20 ; CHECK-LABEL: @test3(
21 ; CHECK-NEXT: [[I:%.*]] = insertelement <4 x i32> [[A:%.*]], i32 5, i64 1
22 ; CHECK-NEXT: ret <4 x i32> [[I]]
23 ;
1524 %I = insertelement <4 x i32> %A, i32 5, i64 1
16 ; CHECK: ret <4 x i32> %I
1725 ret <4 x i32> %I
1826 }
1927
2028 define <4 x i32> @test4(<4 x i32> %A) {
29 ; CHECK-LABEL: @test4(
30 ; CHECK-NEXT: ret <4 x i32> undef
31 ;
2132 %I = insertelement <4 x i32> %A, i32 5, i128 100
22 ; CHECK: ret <4 x i32> undef
2333 ret <4 x i32> %I
2434 }
2535
2636 define <4 x i32> @test5(<4 x i32> %A) {
37 ; CHECK-LABEL: @test5(
38 ; CHECK-NEXT: ret <4 x i32> undef
39 ;
2740 %I = insertelement <4 x i32> %A, i32 5, i64 undef
28 ; CHECK: ret <4 x i32> undef
2941 ret <4 x i32> %I
3042 }
43
44 define <4 x i32> @PR1286(<4 x i32> %A) {
45 ; CHECK-LABEL: @PR1286(
46 ; CHECK-NEXT: ret <4 x i32> [[A:%.*]]
47 ;
48 %B = insertelement <4 x i32> %A, i32 undef, i32 1
49 ret <4 x i32> %B
50 }