[llvm] r361559 - [InstSimplify] insertelement V, undef, ? --> V
Sanjay Patel via llvm-commits
llvm-commits at lists.llvm.org
Thu May 23 14:49:47 PDT 2019
Author: spatel
Date: Thu May 23 14:49:47 2019
New Revision: 361559
URL: http://llvm.org/viewvc/llvm-project?rev=361559&view=rev
Log:
[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.
Removed:
llvm/trunk/test/Transforms/InstCombine/vec_insertelt.ll
Modified:
llvm/trunk/lib/Analysis/InstructionSimplify.cpp
llvm/trunk/lib/Transforms/InstCombine/InstCombineVectorOps.cpp
llvm/trunk/test/Transforms/InstSimplify/insertelement.ll
Modified: llvm/trunk/lib/Analysis/InstructionSimplify.cpp
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/lib/Analysis/InstructionSimplify.cpp?rev=361559&r1=361558&r2=361559&view=diff
==============================================================================
--- llvm/trunk/lib/Analysis/InstructionSimplify.cpp (original)
+++ llvm/trunk/lib/Analysis/InstructionSimplify.cpp Thu May 23 14:49:47 2019
@@ -4011,6 +4011,11 @@ Value *llvm::SimplifyInsertElementInst(V
if (isa<UndefValue>(Idx))
return UndefValue::get(Vec->getType());
+ // Inserting an undef scalar? Assume it is the same value as the existing
+ // vector element.
+ if (isa<UndefValue>(Val))
+ return Vec;
+
return nullptr;
}
Modified: llvm/trunk/lib/Transforms/InstCombine/InstCombineVectorOps.cpp
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/lib/Transforms/InstCombine/InstCombineVectorOps.cpp?rev=361559&r1=361558&r2=361559&view=diff
==============================================================================
--- llvm/trunk/lib/Transforms/InstCombine/InstCombineVectorOps.cpp (original)
+++ llvm/trunk/lib/Transforms/InstCombine/InstCombineVectorOps.cpp Thu May 23 14:49:47 2019
@@ -863,10 +863,6 @@ Instruction *InstCombiner::visitInsertEl
VecOp, ScalarOp, IdxOp, SQ.getWithInstruction(&IE)))
return replaceInstUsesWith(IE, V);
- // Inserting an undef or into an undefined place, remove this.
- if (isa<UndefValue>(ScalarOp) || isa<UndefValue>(IdxOp))
- replaceInstUsesWith(IE, VecOp);
-
// If the vector and scalar are both bitcast from the same element type, do
// the insert in that source type followed by bitcast.
Value *VecSrc, *ScalarSrc;
Removed: llvm/trunk/test/Transforms/InstCombine/vec_insertelt.ll
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/test/Transforms/InstCombine/vec_insertelt.ll?rev=361558&view=auto
==============================================================================
--- llvm/trunk/test/Transforms/InstCombine/vec_insertelt.ll (original)
+++ llvm/trunk/test/Transforms/InstCombine/vec_insertelt.ll (removed)
@@ -1,8 +0,0 @@
-; RUN: opt < %s -instcombine -S | FileCheck %s
-; CHECK: ret <4 x i32> %A
-
-; PR1286
-define <4 x i32> @test1(<4 x i32> %A) {
- %B = insertelement <4 x i32> %A, i32 undef, i32 1
- ret <4 x i32> %B
-}
Modified: llvm/trunk/test/Transforms/InstSimplify/insertelement.ll
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/test/Transforms/InstSimplify/insertelement.ll?rev=361559&r1=361558&r2=361559&view=diff
==============================================================================
--- llvm/trunk/test/Transforms/InstSimplify/insertelement.ll (original)
+++ llvm/trunk/test/Transforms/InstSimplify/insertelement.ll Thu May 23 14:49:47 2019
@@ -1,31 +1,51 @@
+; NOTE: Assertions have been autogenerated by utils/update_test_checks.py
; RUN: opt -S -instsimplify < %s | FileCheck %s
define <4 x i32> @test1(<4 x i32> %A) {
+; CHECK-LABEL: @test1(
+; CHECK-NEXT: ret <4 x i32> undef
+;
%I = insertelement <4 x i32> %A, i32 5, i64 4294967296
- ; CHECK: ret <4 x i32> undef
ret <4 x i32> %I
}
define <4 x i32> @test2(<4 x i32> %A) {
+; CHECK-LABEL: @test2(
+; CHECK-NEXT: ret <4 x i32> undef
+;
%I = insertelement <4 x i32> %A, i32 5, i64 4
- ; CHECK: ret <4 x i32> undef
ret <4 x i32> %I
}
define <4 x i32> @test3(<4 x i32> %A) {
+; CHECK-LABEL: @test3(
+; CHECK-NEXT: [[I:%.*]] = insertelement <4 x i32> [[A:%.*]], i32 5, i64 1
+; CHECK-NEXT: ret <4 x i32> [[I]]
+;
%I = insertelement <4 x i32> %A, i32 5, i64 1
- ; CHECK: ret <4 x i32> %I
ret <4 x i32> %I
}
define <4 x i32> @test4(<4 x i32> %A) {
+; CHECK-LABEL: @test4(
+; CHECK-NEXT: ret <4 x i32> undef
+;
%I = insertelement <4 x i32> %A, i32 5, i128 100
- ; CHECK: ret <4 x i32> undef
ret <4 x i32> %I
}
define <4 x i32> @test5(<4 x i32> %A) {
+; CHECK-LABEL: @test5(
+; CHECK-NEXT: ret <4 x i32> undef
+;
%I = insertelement <4 x i32> %A, i32 5, i64 undef
- ; CHECK: ret <4 x i32> undef
ret <4 x i32> %I
}
+
+define <4 x i32> @PR1286(<4 x i32> %A) {
+; CHECK-LABEL: @PR1286(
+; CHECK-NEXT: ret <4 x i32> [[A:%.*]]
+;
+ %B = insertelement <4 x i32> %A, i32 undef, i32 1
+ ret <4 x i32> %B
+}
More information about the llvm-commits
mailing list