Revert "Revert "New interface function is added to VectorUtils Value *getSplatValue(Value *Val);""
This reverts commit r246379. It seems that the commit was not the culprit, and the bot will be investigated for instability. llvm-svn: 246380
This commit is contained in:
parent
c7be31736c
commit
3b1d3b0d84
|
@ -79,6 +79,11 @@ Value *getStrideFromPointer(Value *Ptr, ScalarEvolution *SE, Loop *Lp);
|
||||||
/// from the vector.
|
/// from the vector.
|
||||||
Value *findScalarElement(Value *V, unsigned EltNo);
|
Value *findScalarElement(Value *V, unsigned EltNo);
|
||||||
|
|
||||||
|
/// \brief Get splat value if the input is a splat vector or return nullptr.
|
||||||
|
/// The value may be extracted from a splat constants vector or from
|
||||||
|
/// a sequence of instructions that broadcast a single value into a vector.
|
||||||
|
Value *getSplatValue(Value *V);
|
||||||
|
|
||||||
} // llvm namespace
|
} // llvm namespace
|
||||||
|
|
||||||
#endif
|
#endif
|
||||||
|
|
|
@ -18,6 +18,8 @@
|
||||||
#include "llvm/IR/GetElementPtrTypeIterator.h"
|
#include "llvm/IR/GetElementPtrTypeIterator.h"
|
||||||
#include "llvm/IR/PatternMatch.h"
|
#include "llvm/IR/PatternMatch.h"
|
||||||
#include "llvm/IR/Value.h"
|
#include "llvm/IR/Value.h"
|
||||||
|
#include "llvm/IR/Constants.h"
|
||||||
|
|
||||||
using namespace llvm;
|
using namespace llvm;
|
||||||
using namespace llvm::PatternMatch;
|
using namespace llvm::PatternMatch;
|
||||||
|
|
||||||
|
@ -406,3 +408,27 @@ Value *llvm::findScalarElement(Value *V, unsigned EltNo) {
|
||||||
// Otherwise, we don't know.
|
// Otherwise, we don't know.
|
||||||
return nullptr;
|
return nullptr;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/// \brief Get splat value if the input is a splat vector or return nullptr.
|
||||||
|
/// The value may be extracted from a splat constants vector or from
|
||||||
|
/// a sequence of instructions that broadcast a single value into a vector.
|
||||||
|
llvm::Value *llvm::getSplatValue(Value *V) {
|
||||||
|
llvm::ConstantDataVector *CV = dyn_cast<llvm::ConstantDataVector>(V);
|
||||||
|
if (CV)
|
||||||
|
return CV->getSplatValue();
|
||||||
|
llvm::ShuffleVectorInst *ShuffleInst = dyn_cast<llvm::ShuffleVectorInst>(V);
|
||||||
|
if (!ShuffleInst)
|
||||||
|
return nullptr;
|
||||||
|
// All-zero (our undef) shuffle mask elements.
|
||||||
|
for (int i : ShuffleInst->getShuffleMask())
|
||||||
|
if (i != 0 && i != -1)
|
||||||
|
return nullptr;
|
||||||
|
// The first shuffle source is 'insertelement' with index 0.
|
||||||
|
llvm::InsertElementInst *InsertEltInst =
|
||||||
|
dyn_cast<llvm::InsertElementInst>(ShuffleInst->getOperand(0));
|
||||||
|
if (!InsertEltInst || !isa<ConstantInt>(InsertEltInst->getOperand(2)) ||
|
||||||
|
!cast<ConstantInt>(InsertEltInst->getOperand(2))->isNullValue())
|
||||||
|
return nullptr;
|
||||||
|
|
||||||
|
return InsertEltInst->getOperand(1);
|
||||||
|
}
|
||||||
|
|
|
@ -22,6 +22,7 @@
|
||||||
#include "llvm/Analysis/ConstantFolding.h"
|
#include "llvm/Analysis/ConstantFolding.h"
|
||||||
#include "llvm/Analysis/TargetLibraryInfo.h"
|
#include "llvm/Analysis/TargetLibraryInfo.h"
|
||||||
#include "llvm/Analysis/ValueTracking.h"
|
#include "llvm/Analysis/ValueTracking.h"
|
||||||
|
#include "llvm/Analysis/VectorUtils.h"
|
||||||
#include "llvm/CodeGen/FastISel.h"
|
#include "llvm/CodeGen/FastISel.h"
|
||||||
#include "llvm/CodeGen/FunctionLoweringInfo.h"
|
#include "llvm/CodeGen/FunctionLoweringInfo.h"
|
||||||
#include "llvm/CodeGen/GCMetadata.h"
|
#include "llvm/CodeGen/GCMetadata.h"
|
||||||
|
@ -3150,37 +3151,32 @@ static bool getUniformBase(Value *& Ptr, SDValue& Base, SDValue& Index,
|
||||||
SelectionDAGBuilder* SDB) {
|
SelectionDAGBuilder* SDB) {
|
||||||
|
|
||||||
assert(Ptr->getType()->isVectorTy() && "Unexpected pointer type");
|
assert(Ptr->getType()->isVectorTy() && "Unexpected pointer type");
|
||||||
GetElementPtrInst *Gep = dyn_cast<GetElementPtrInst>(Ptr);
|
GetElementPtrInst *GEP = dyn_cast<GetElementPtrInst>(Ptr);
|
||||||
if (!Gep || Gep->getNumOperands() > 2)
|
if (!GEP || GEP->getNumOperands() > 2)
|
||||||
return false;
|
return false;
|
||||||
ShuffleVectorInst *ShuffleInst =
|
Value *GEPPtrs = GEP->getPointerOperand();
|
||||||
dyn_cast<ShuffleVectorInst>(Gep->getPointerOperand());
|
if (!(Ptr = getSplatValue(GEPPtrs)))
|
||||||
if (!ShuffleInst || !ShuffleInst->getMask()->isNullValue() ||
|
|
||||||
cast<Instruction>(ShuffleInst->getOperand(0))->getOpcode() !=
|
|
||||||
Instruction::InsertElement)
|
|
||||||
return false;
|
return false;
|
||||||
|
|
||||||
Ptr = cast<InsertElementInst>(ShuffleInst->getOperand(0))->getOperand(1);
|
|
||||||
|
|
||||||
SelectionDAG& DAG = SDB->DAG;
|
SelectionDAG& DAG = SDB->DAG;
|
||||||
const TargetLowering &TLI = DAG.getTargetLoweringInfo();
|
const TargetLowering &TLI = DAG.getTargetLoweringInfo();
|
||||||
// Check is the Ptr is inside current basic block
|
// Check is the Ptr is inside current basic block
|
||||||
// If not, look for the shuffle instruction
|
// If not, look for the shuffle instruction
|
||||||
if (SDB->findValue(Ptr))
|
if (SDB->findValue(Ptr))
|
||||||
Base = SDB->getValue(Ptr);
|
Base = SDB->getValue(Ptr);
|
||||||
else if (SDB->findValue(ShuffleInst)) {
|
else if (SDB->findValue(GEPPtrs)) {
|
||||||
SDValue ShuffleNode = SDB->getValue(ShuffleInst);
|
SDValue GEPPtrsVal = SDB->getValue(GEPPtrs);
|
||||||
SDLoc sdl = ShuffleNode;
|
SDLoc sdl = GEPPtrsVal;
|
||||||
Base = DAG.getNode(
|
EVT IdxVT = TLI.getVectorIdxTy(DAG.getDataLayout());
|
||||||
ISD::EXTRACT_VECTOR_ELT, sdl,
|
Base = DAG.getNode(ISD::EXTRACT_VECTOR_ELT, sdl,
|
||||||
ShuffleNode.getValueType().getScalarType(), ShuffleNode,
|
GEPPtrsVal.getValueType().getScalarType(), GEPPtrsVal,
|
||||||
DAG.getConstant(0, sdl, TLI.getVectorIdxTy(DAG.getDataLayout())));
|
DAG.getConstant(0, sdl, IdxVT));
|
||||||
SDB->setValue(Ptr, Base);
|
SDB->setValue(Ptr, Base);
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
return false;
|
return false;
|
||||||
|
|
||||||
Value *IndexVal = Gep->getOperand(1);
|
Value *IndexVal = GEP->getOperand(1);
|
||||||
if (SDB->findValue(IndexVal)) {
|
if (SDB->findValue(IndexVal)) {
|
||||||
Index = SDB->getValue(IndexVal);
|
Index = SDB->getValue(IndexVal);
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue