[llvm] 86bf234 - [IR] Change the default value of InstertElement to poison (1/4)
hyeongyu kim via llvm-commits
llvm-commits at lists.llvm.org
Tue Sep 28 06:29:23 PDT 2021
Author: hyeongyu kim
Date: 2021-09-28T22:29:16+09:00
New Revision: 86bf234d0b7038479292a0d771dc05966140b908
URL: https://github.com/llvm/llvm-project/commit/86bf234d0b7038479292a0d771dc05966140b908
DIFF: https://github.com/llvm/llvm-project/commit/86bf234d0b7038479292a0d771dc05966140b908.diff
LOG: [IR] Change the default value of InstertElement to poison (1/4)
This patch is for fixing potential insertElement-related bugs like D93818.
```
V = UndefValue::get(VecTy);
for(...)
V = Builder.CreateInsertElementy(V, Elt, Idx);
=>
V = PoisonValue::get(VecTy);
for(...)
V = Builder.CreateInsertElementy(V, Elt, Idx);
```
Like above, this patch changes the placeholder V to poison.
The patch will be separated into several commits.
Reviewed By: aqjune
Differential Revision: https://reviews.llvm.org/D110311
Added:
Modified:
llvm/include/llvm/IR/IRBuilder.h
llvm/lib/IR/AutoUpgrade.cpp
llvm/lib/Target/NVPTX/NVPTXGenericToNVVM.cpp
llvm/unittests/IR/IRBuilderTest.cpp
llvm/unittests/IR/PatternMatch.cpp
Removed:
################################################################################
diff --git a/llvm/include/llvm/IR/IRBuilder.h b/llvm/include/llvm/IR/IRBuilder.h
index 2c07f431b5703..8b2108ec49945 100644
--- a/llvm/include/llvm/IR/IRBuilder.h
+++ b/llvm/include/llvm/IR/IRBuilder.h
@@ -2452,6 +2452,16 @@ class IRBuilderBase {
return CreateExtractElement(Vec, getInt64(Idx), Name);
}
+ Value *CreateInsertElement(Type *VecTy, Value *NewElt, Value *Idx,
+ const Twine &Name = "") {
+ return CreateInsertElement(PoisonValue::get(VecTy), NewElt, Idx, Name);
+ }
+
+ Value *CreateInsertElement(Type *VecTy, Value *NewElt, uint64_t Idx,
+ const Twine &Name = "") {
+ return CreateInsertElement(PoisonValue::get(VecTy), NewElt, Idx, Name);
+ }
+
Value *CreateInsertElement(Value *Vec, Value *NewElt, Value *Idx,
const Twine &Name = "") {
if (auto *VC = dyn_cast<Constant>(Vec))
diff --git a/llvm/lib/IR/AutoUpgrade.cpp b/llvm/lib/IR/AutoUpgrade.cpp
index aaa9b04ffbba9..9bb85a300fa21 100644
--- a/llvm/lib/IR/AutoUpgrade.cpp
+++ b/llvm/lib/IR/AutoUpgrade.cpp
@@ -2417,7 +2417,7 @@ void llvm::UpgradeIntrinsicCall(CallInst *CI, Function *NewFn) {
EltTy->getPointerTo());
Value *Load = Builder.CreateLoad(EltTy, Cast);
Type *I32Ty = Type::getInt32Ty(C);
- Rep = UndefValue::get(VecTy);
+ Rep = PoisonValue::get(VecTy);
for (unsigned I = 0; I < EltNum; ++I)
Rep = Builder.CreateInsertElement(Rep, Load,
ConstantInt::get(I32Ty, I));
diff --git a/llvm/lib/Target/NVPTX/NVPTXGenericToNVVM.cpp b/llvm/lib/Target/NVPTX/NVPTXGenericToNVVM.cpp
index 063ea18574b94..a9a5eae42c1d0 100644
--- a/llvm/lib/Target/NVPTX/NVPTXGenericToNVVM.cpp
+++ b/llvm/lib/Target/NVPTX/NVPTXGenericToNVVM.cpp
@@ -212,7 +212,7 @@ Value *GenericToNVVM::remapConstantVectorOrConstantAggregate(
// If any of the elements has been modified, construct the equivalent
// vector or aggregate value with a set instructions and the converted
// elements.
- Value *NewValue = UndefValue::get(C->getType());
+ Value *NewValue = PoisonValue::get(C->getType());
if (isa<ConstantVector>(C)) {
for (unsigned i = 0; i < NumOperands; ++i) {
Value *Idx = ConstantInt::get(Type::getInt32Ty(M->getContext()), i);
diff --git a/llvm/unittests/IR/IRBuilderTest.cpp b/llvm/unittests/IR/IRBuilderTest.cpp
index 11292b9668285..052f69e7ebd17 100644
--- a/llvm/unittests/IR/IRBuilderTest.cpp
+++ b/llvm/unittests/IR/IRBuilderTest.cpp
@@ -878,8 +878,7 @@ TEST_F(IRBuilderTest, InsertExtractElement) {
auto VecTy = FixedVectorType::get(Builder.getInt64Ty(), 4);
auto Elt1 = Builder.getInt64(-1);
auto Elt2 = Builder.getInt64(-2);
- Value *Vec = UndefValue::get(VecTy);
- Vec = Builder.CreateInsertElement(Vec, Elt1, Builder.getInt8(1));
+ Value *Vec = Builder.CreateInsertElement(VecTy, Elt1, Builder.getInt8(1));
Vec = Builder.CreateInsertElement(Vec, Elt2, 2);
auto X1 = Builder.CreateExtractElement(Vec, 1);
auto X2 = Builder.CreateExtractElement(Vec, Builder.getInt32(2));
diff --git a/llvm/unittests/IR/PatternMatch.cpp b/llvm/unittests/IR/PatternMatch.cpp
index 5a67899ee50fb..945135adaa18a 100644
--- a/llvm/unittests/IR/PatternMatch.cpp
+++ b/llvm/unittests/IR/PatternMatch.cpp
@@ -940,8 +940,7 @@ TEST_F(PatternMatchTest, VectorOps) {
VecElemIdxs.push_back(ConstantInt::get(i32, 2));
auto *IdxVec = ConstantVector::get(VecElemIdxs);
- Value *UndefVec = UndefValue::get(VecTy);
- Value *VI1 = IRB.CreateInsertElement(UndefVec, IRB.getInt8(1), (uint64_t)0);
+ Value *VI1 = IRB.CreateInsertElement(VecTy, IRB.getInt8(1), (uint64_t)0);
Value *VI2 = IRB.CreateInsertElement(VI1, Val2, Val);
Value *VI3 = IRB.CreateInsertElement(VI1, Val2, (uint64_t)1);
Value *VI4 = IRB.CreateInsertElement(VI1, IRB.getInt8(2), Val);
More information about the llvm-commits
mailing list