[llvm-branch-commits] [llvm] 3a60a1f - [InstSimplify] Fold insertelement vec, poison, idx into vec
Juneyoung Lee via llvm-branch-commits
llvm-branch-commits at lists.llvm.org
Wed Jan 6 17:14:56 PST 2021
Author: Juneyoung Lee
Date: 2021-01-07T10:10:14+09:00
New Revision: 3a60a1f165708954ce8d279f9692116844a998fa
URL: https://github.com/llvm/llvm-project/commit/3a60a1f165708954ce8d279f9692116844a998fa
DIFF: https://github.com/llvm/llvm-project/commit/3a60a1f165708954ce8d279f9692116844a998fa.diff
LOG: [InstSimplify] Fold insertelement vec, poison, idx into vec
This is a simple patch that adds folding from `insertelement vec, poison, idx` into `vec`.
Alive2 proof: https://alive2.llvm.org/ce/z/2y2vbC
Reviewed By: nikic
Differential Revision: https://reviews.llvm.org/D93994
Added:
Modified:
llvm/lib/Analysis/InstructionSimplify.cpp
llvm/test/Transforms/InstCombine/extractelement-inseltpoison.ll
llvm/test/Transforms/InstCombine/extractelement.ll
llvm/test/Transforms/InstSimplify/insertelement.ll
llvm/test/Transforms/SLPVectorizer/X86/alternate-int.ll
Removed:
################################################################################
diff --git a/llvm/lib/Analysis/InstructionSimplify.cpp b/llvm/lib/Analysis/InstructionSimplify.cpp
index 5c251452e96d1..96a3ada89db4a 100644
--- a/llvm/lib/Analysis/InstructionSimplify.cpp
+++ b/llvm/lib/Analysis/InstructionSimplify.cpp
@@ -4401,10 +4401,10 @@ Value *llvm::SimplifyInsertElementInst(Value *Vec, Value *Val, Value *Idx,
if (Q.isUndefValue(Idx))
return PoisonValue::get(Vec->getType());
- // If the scalar is undef, and there is no risk of propagating poison from the
- // vector value, simplify to the vector value.
- if (Q.isUndefValue(Val) &&
- isGuaranteedNotToBeUndefOrPoison(Vec))
+ // If the scalar is poison, or it is undef and there is no risk of
+ // propagating poison from the vector value, simplify to the vector value.
+ if (isa<PoisonValue>(Val) ||
+ (Q.isUndefValue(Val) && isGuaranteedNotToBePoison(Vec)))
return Vec;
// If we are extracting a value from a vector, then inserting it into the same
diff --git a/llvm/test/Transforms/InstCombine/extractelement-inseltpoison.ll b/llvm/test/Transforms/InstCombine/extractelement-inseltpoison.ll
index f3fad9bb375c1..0792e7aff5168 100644
--- a/llvm/test/Transforms/InstCombine/extractelement-inseltpoison.ll
+++ b/llvm/test/Transforms/InstCombine/extractelement-inseltpoison.ll
@@ -319,8 +319,7 @@ define <4 x double> @invalid_extractelement(<2 x double> %a, <4 x double> %b, do
; ANY-NEXT: [[T4:%.*]] = shufflevector <4 x double> [[B:%.*]], <4 x double> [[TMP1]], <4 x i32> <i32 undef, i32 1, i32 4, i32 3>
; ANY-NEXT: [[E:%.*]] = extractelement <4 x double> [[B]], i32 1
; ANY-NEXT: store double [[E]], double* [[P:%.*]], align 8
-; ANY-NEXT: [[R:%.*]] = insertelement <4 x double> [[T4]], double poison, i64 0
-; ANY-NEXT: ret <4 x double> [[R]]
+; ANY-NEXT: ret <4 x double> [[T4]]
;
%t3 = extractelement <2 x double> %a, i32 0
%t4 = insertelement <4 x double> %b, double %t3, i32 2
diff --git a/llvm/test/Transforms/InstCombine/extractelement.ll b/llvm/test/Transforms/InstCombine/extractelement.ll
index 7d36618452f5f..4bb2a32681e56 100644
--- a/llvm/test/Transforms/InstCombine/extractelement.ll
+++ b/llvm/test/Transforms/InstCombine/extractelement.ll
@@ -319,8 +319,7 @@ define <4 x double> @invalid_extractelement(<2 x double> %a, <4 x double> %b, do
; ANY-NEXT: [[T4:%.*]] = shufflevector <4 x double> [[B:%.*]], <4 x double> [[TMP1]], <4 x i32> <i32 undef, i32 1, i32 4, i32 3>
; ANY-NEXT: [[E:%.*]] = extractelement <4 x double> [[B]], i32 1
; ANY-NEXT: store double [[E]], double* [[P:%.*]], align 8
-; ANY-NEXT: [[R:%.*]] = insertelement <4 x double> [[T4]], double poison, i64 0
-; ANY-NEXT: ret <4 x double> [[R]]
+; ANY-NEXT: ret <4 x double> [[T4]]
;
%t3 = extractelement <2 x double> %a, i32 0
%t4 = insertelement <4 x double> %b, double %t3, i32 2
diff --git a/llvm/test/Transforms/InstSimplify/insertelement.ll b/llvm/test/Transforms/InstSimplify/insertelement.ll
index 580670844f22e..8cb3312cf9eb6 100644
--- a/llvm/test/Transforms/InstSimplify/insertelement.ll
+++ b/llvm/test/Transforms/InstSimplify/insertelement.ll
@@ -52,8 +52,7 @@ define <4 x i32> @test5_poison(<4 x i32> %A) {
define <4 x i32> @elem_poison(<4 x i32> %A) {
; CHECK-LABEL: @elem_poison(
-; CHECK-NEXT: [[B:%.*]] = insertelement <4 x i32> [[A:%.*]], i32 poison, i32 1
-; CHECK-NEXT: ret <4 x i32> [[B]]
+; CHECK-NEXT: ret <4 x i32> [[A:%.*]]
;
%B = insertelement <4 x i32> %A, i32 poison, i32 1
ret <4 x i32> %B
diff --git a/llvm/test/Transforms/SLPVectorizer/X86/alternate-int.ll b/llvm/test/Transforms/SLPVectorizer/X86/alternate-int.ll
index a71379791f20a..176b2a3c49a01 100644
--- a/llvm/test/Transforms/SLPVectorizer/X86/alternate-int.ll
+++ b/llvm/test/Transforms/SLPVectorizer/X86/alternate-int.ll
@@ -425,10 +425,10 @@ define <8 x i32> @sdiv_v8i32_undefs(<8 x i32> %a) {
; CHECK-NEXT: [[AB5:%.*]] = sdiv i32 [[A5]], 4
; CHECK-NEXT: [[AB6:%.*]] = sdiv i32 [[A6]], 8
; CHECK-NEXT: [[AB7:%.*]] = sdiv i32 [[A7]], 16
-; CHECK-NEXT: [[TMP1:%.*]] = insertelement <8 x i32> poison, i32 [[AB1]], i32 1
-; CHECK-NEXT: [[TMP2:%.*]] = insertelement <8 x i32> [[TMP1]], i32 [[AB2]], i32 2
-; CHECK-NEXT: [[R4:%.*]] = insertelement <8 x i32> [[TMP2]], i32 [[AB3]], i32 3
-; CHECK-NEXT: [[R5:%.*]] = insertelement <8 x i32> [[R4]], i32 [[AB5]], i32 5
+; CHECK-NEXT: [[R1:%.*]] = insertelement <8 x i32> <i32 poison, i32 poison, i32 poison, i32 poison, i32 undef, i32 poison, i32 poison, i32 poison>, i32 [[AB1]], i32 1
+; CHECK-NEXT: [[R2:%.*]] = insertelement <8 x i32> [[R1]], i32 [[AB2]], i32 2
+; CHECK-NEXT: [[R3:%.*]] = insertelement <8 x i32> [[R2]], i32 [[AB3]], i32 3
+; CHECK-NEXT: [[R5:%.*]] = insertelement <8 x i32> [[R3]], i32 [[AB5]], i32 5
; CHECK-NEXT: [[R6:%.*]] = insertelement <8 x i32> [[R5]], i32 [[AB6]], i32 6
; CHECK-NEXT: [[R7:%.*]] = insertelement <8 x i32> [[R6]], i32 [[AB7]], i32 7
; CHECK-NEXT: ret <8 x i32> [[R7]]
More information about the llvm-branch-commits
mailing list