[llvm] 5486e00 - [InstSimplify] remove poison-unsafe insertelement of undef value
Sanjay Patel via llvm-commits
llvm-commits at lists.llvm.org
Fri May 1 06:33:13 PDT 2020
Author: Sanjay Patel
Date: 2020-05-01T09:22:05-04:00
New Revision: 5486e00dc3e3bb9969f1e8dbddfd18bb92c99e56
URL: https://github.com/llvm/llvm-project/commit/5486e00dc3e3bb9969f1e8dbddfd18bb92c99e56
DIFF: https://github.com/llvm/llvm-project/commit/5486e00dc3e3bb9969f1e8dbddfd18bb92c99e56.diff
LOG: [InstSimplify] remove poison-unsafe insertelement of undef value
PR45481:
https://bugs.llvm.org/show_bug.cgi?id=45481
SDAG has an identical transform to this, so there's little
chance of any real-world impact. OTOH, that means we are
effectively sweeping the bug out of sight because poison
exists in codegen too.
Added:
Modified:
llvm/lib/Analysis/InstructionSimplify.cpp
llvm/test/Transforms/InstCombine/extractelement.ll
llvm/test/Transforms/InstSimplify/insertelement.ll
Removed:
################################################################################
diff --git a/llvm/lib/Analysis/InstructionSimplify.cpp b/llvm/lib/Analysis/InstructionSimplify.cpp
index 7765cb706273..6eb995d8b788 100644
--- a/llvm/lib/Analysis/InstructionSimplify.cpp
+++ b/llvm/lib/Analysis/InstructionSimplify.cpp
@@ -4302,11 +4302,6 @@ Value *llvm::SimplifyInsertElementInst(Value *Vec, Value *Val, Value *Idx,
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;
-
// If we are extracting a value from a vector, then inserting it into the same
// place, that's the input vector:
// insertelt Vec, (extractelt Vec, Idx), Idx --> Vec
diff --git a/llvm/test/Transforms/InstCombine/extractelement.ll b/llvm/test/Transforms/InstCombine/extractelement.ll
index b1f57060b02b..76b7d28b2c09 100644
--- a/llvm/test/Transforms/InstCombine/extractelement.ll
+++ b/llvm/test/Transforms/InstCombine/extractelement.ll
@@ -319,7 +319,8 @@ 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: ret <4 x double> [[T4]]
+; ANY-NEXT: [[R:%.*]] = insertelement <4 x double> [[T4]], double undef, i64 0
+; ANY-NEXT: ret <4 x double> [[R]]
;
%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 97f656a7c829..e54a03f29c9f 100644
--- a/llvm/test/Transforms/InstSimplify/insertelement.ll
+++ b/llvm/test/Transforms/InstSimplify/insertelement.ll
@@ -42,14 +42,26 @@ define <4 x i32> @test5(<4 x i32> %A) {
ret <4 x i32> %I
}
+; The undef may be replacing a poison value, so it is not safe to just return 'A'.
+
define <4 x i32> @PR1286(<4 x i32> %A) {
; CHECK-LABEL: @PR1286(
-; CHECK-NEXT: ret <4 x i32> [[A:%.*]]
+; CHECK-NEXT: [[B:%.*]] = insertelement <4 x i32> [[A:%.*]], i32 undef, i32 1
+; CHECK-NEXT: ret <4 x i32> [[B]]
;
%B = insertelement <4 x i32> %A, i32 undef, i32 1
ret <4 x i32> %B
}
+define <2 x i32> @undef_into_constant_vector_with_variable_index(<2 x i32> %A, i32 %Index) {
+; CHECK-LABEL: @undef_into_constant_vector_with_variable_index(
+; CHECK-NEXT: [[B:%.*]] = insertelement <2 x i32> <i32 42, i32 -42>, i32 undef, i32 [[INDEX:%.*]]
+; CHECK-NEXT: ret <2 x i32> [[B]]
+;
+ %B = insertelement <2 x i32> <i32 42, i32 -42>, i32 undef, i32 %Index
+ ret <2 x i32> %B
+}
+
define <8 x i8> @extract_insert_same_vec_and_index(<8 x i8> %in) {
; CHECK-LABEL: @extract_insert_same_vec_and_index(
; CHECK-NEXT: ret <8 x i8> [[IN:%.*]]
More information about the llvm-commits
mailing list