aboutsummaryrefslogtreecommitdiff
path: root/llvm/lib
diff options
context:
space:
mode:
authorJuneyoung Lee <aqjune@gmail.com>2021-05-31 18:40:40 +0900
committerJuneyoung Lee <aqjune@gmail.com>2021-05-31 18:47:09 +0900
commit7161bb87c914684562bfb20fec7d60e533150f7a (patch)
tree3679cdfd6c59a51837316aba4e446200119caf3e /llvm/lib
parent222aeb4d51a46c5a81c9e4ccb16d1d19dd21ec95 (diff)
downloadllvm-7161bb87c914684562bfb20fec7d60e533150f7a.zip
llvm-7161bb87c914684562bfb20fec7d60e533150f7a.tar.gz
llvm-7161bb87c914684562bfb20fec7d60e533150f7a.tar.bz2
[InsCombine] Fix a few remaining vec transforms to use poison instead of undef
This is a patch that replaces shufflevector and insertelement's placeholder value with poison. Underlying motivation is to fix the semantics of shufflevector with undef mask to return poison instead (D93818) The consensus has been made in the late 2020 via mailing list as well as the thread in https://bugs.llvm.org/show_bug.cgi?id=44185 . This patch is a simple syntactic change to the existing code, hence directly pushed as a commit.
Diffstat (limited to 'llvm/lib')
-rw-r--r--llvm/lib/Transforms/InstCombine/InstCombineCalls.cpp3
-rw-r--r--llvm/lib/Transforms/InstCombine/InstCombineCasts.cpp2
-rw-r--r--llvm/lib/Transforms/InstCombine/InstCombineSimplifyDemanded.cpp2
-rw-r--r--llvm/lib/Transforms/InstCombine/InstCombineVectorOps.cpp16
4 files changed, 11 insertions, 12 deletions
diff --git a/llvm/lib/Transforms/InstCombine/InstCombineCalls.cpp b/llvm/lib/Transforms/InstCombine/InstCombineCalls.cpp
index 583a6c6..193730e 100644
--- a/llvm/lib/Transforms/InstCombine/InstCombineCalls.cpp
+++ b/llvm/lib/Transforms/InstCombine/InstCombineCalls.cpp
@@ -1935,8 +1935,7 @@ Instruction *InstCombinerImpl::visitCallInst(CallInst &CI) {
for (unsigned i = 0; i != DstNumElts; ++i)
Mask.push_back(IdxN + i);
- Value *Shuffle =
- Builder.CreateShuffleVector(Vec, UndefValue::get(VecTy), Mask);
+ Value *Shuffle = Builder.CreateShuffleVector(Vec, Mask);
replaceInstUsesWith(CI, Shuffle);
return eraseInstFromFunction(CI);
}
diff --git a/llvm/lib/Transforms/InstCombine/InstCombineCasts.cpp b/llvm/lib/Transforms/InstCombine/InstCombineCasts.cpp
index e69dbd7..ca5f02d 100644
--- a/llvm/lib/Transforms/InstCombine/InstCombineCasts.cpp
+++ b/llvm/lib/Transforms/InstCombine/InstCombineCasts.cpp
@@ -2653,7 +2653,7 @@ Instruction *InstCombinerImpl::visitBitCast(BitCastInst &CI) {
// Beware: messing with this target-specific oddity may cause trouble.
if (DestVTy->getNumElements() == 1 && SrcTy->isX86_MMXTy()) {
Value *Elem = Builder.CreateBitCast(Src, DestVTy->getElementType());
- return InsertElementInst::Create(UndefValue::get(DestTy), Elem,
+ return InsertElementInst::Create(PoisonValue::get(DestTy), Elem,
Constant::getNullValue(Type::getInt32Ty(CI.getContext())));
}
diff --git a/llvm/lib/Transforms/InstCombine/InstCombineSimplifyDemanded.cpp b/llvm/lib/Transforms/InstCombine/InstCombineSimplifyDemanded.cpp
index 8957598..15b51ae 100644
--- a/llvm/lib/Transforms/InstCombine/InstCombineSimplifyDemanded.cpp
+++ b/llvm/lib/Transforms/InstCombine/InstCombineSimplifyDemanded.cpp
@@ -1262,7 +1262,7 @@ Value *InstCombinerImpl::SimplifyDemandedVectorElts(Value *V,
if (all_of(Shuffle->getShuffleMask(), [](int Elt) { return Elt == 0; }) &&
DemandedElts.isAllOnesValue()) {
if (!match(I->getOperand(1), m_Undef())) {
- I->setOperand(1, UndefValue::get(I->getOperand(1)->getType()));
+ I->setOperand(1, PoisonValue::get(I->getOperand(1)->getType()));
MadeChange = true;
}
APInt LeftDemanded(OpWidth, 1);
diff --git a/llvm/lib/Transforms/InstCombine/InstCombineVectorOps.cpp b/llvm/lib/Transforms/InstCombine/InstCombineVectorOps.cpp
index 030418d5..dc9e2d4 100644
--- a/llvm/lib/Transforms/InstCombine/InstCombineVectorOps.cpp
+++ b/llvm/lib/Transforms/InstCombine/InstCombineVectorOps.cpp
@@ -595,9 +595,9 @@ static void replaceExtractElements(InsertElementInst *InsElt,
NumExtElts >= NumInsElts)
return;
- // Create a shuffle mask to widen the extended-from vector using undefined
+ // Create a shuffle mask to widen the extended-from vector using poison
// values. The mask selects all of the values of the original vector followed
- // by as many undefined values as needed to create a vector of the same length
+ // by as many poison values as needed to create a vector of the same length
// as the inserted-to vector.
SmallVector<int, 16> ExtendMask;
for (unsigned i = 0; i < NumExtElts; ++i)
@@ -632,7 +632,7 @@ static void replaceExtractElements(InsertElementInst *InsElt,
return;
auto *WideVec =
- new ShuffleVectorInst(ExtVecOp, UndefValue::get(ExtVecType), ExtendMask);
+ new ShuffleVectorInst(ExtVecOp, PoisonValue::get(ExtVecType), ExtendMask);
// Insert the new shuffle after the vector operand of the extract is defined
// (as long as it's not a PHI) or at the start of the basic block of the
@@ -1091,7 +1091,7 @@ static bool isShuffleEquivalentToSelect(ShuffleVectorInst &Shuf) {
/// Turn a chain of inserts that splats a value into an insert + shuffle:
/// insertelt(insertelt(insertelt(insertelt X, %k, 0), %k, 1), %k, 2) ... ->
-/// shufflevector(insertelt(X, %k, 0), undef, zero)
+/// shufflevector(insertelt(X, %k, 0), poison, zero)
static Instruction *foldInsSequenceIntoSplat(InsertElementInst &InsElt) {
// We are interested in the last insert in a chain. So if this insert has a
// single user and that user is an insert, bail.
@@ -1149,10 +1149,10 @@ static Instruction *foldInsSequenceIntoSplat(InsertElementInst &InsElt) {
// Create the insert + shuffle.
Type *Int32Ty = Type::getInt32Ty(InsElt.getContext());
- UndefValue *UndefVec = UndefValue::get(VecTy);
+ PoisonValue *PoisonVec = PoisonValue::get(VecTy);
Constant *Zero = ConstantInt::get(Int32Ty, 0);
if (!cast<ConstantInt>(FirstIE->getOperand(2))->isZero())
- FirstIE = InsertElementInst::Create(UndefVec, SplatVal, Zero, "", &InsElt);
+ FirstIE = InsertElementInst::Create(PoisonVec, SplatVal, Zero, "", &InsElt);
// Splat from element 0, but replace absent elements with undef in the mask.
SmallVector<int, 16> Mask(NumElements, 0);
@@ -1160,7 +1160,7 @@ static Instruction *foldInsSequenceIntoSplat(InsertElementInst &InsElt) {
if (!ElementPresent[i])
Mask[i] = -1;
- return new ShuffleVectorInst(FirstIE, UndefVec, Mask);
+ return new ShuffleVectorInst(FirstIE, PoisonVec, Mask);
}
/// Try to fold an insert element into an existing splat shuffle by changing
@@ -1681,7 +1681,7 @@ static Value *evaluateInDifferentElementOrder(Value *V, ArrayRef<int> Mask) {
return ConstantAggregateZero::get(FixedVectorType::get(EltTy, Mask.size()));
if (Constant *C = dyn_cast<Constant>(V))
- return ConstantExpr::getShuffleVector(C, UndefValue::get(C->getType()),
+ return ConstantExpr::getShuffleVector(C, PoisonValue::get(C->getType()),
Mask);
Instruction *I = cast<Instruction>(V);