Merge pull request #1146 from Vsevolod-Livinskij/intr_pass

Rearrange IntrinsicsOpt pass. This fixes bunch of fails, which show up from time to time due to memory corruption.
This commit is contained in:
Dmitry Babokin
2016-01-20 20:25:36 +03:00

60
opt.cpp
View File

@@ -934,7 +934,7 @@ Optimize(llvm::Module *module, int optLevel) {
*/
class IntrinsicsOpt : public llvm::BasicBlockPass {
public:
IntrinsicsOpt();
IntrinsicsOpt() : BasicBlockPass(ID) {};
const char *getPassName() const { return "Intrinsics Cleanup Optimization"; }
bool runOnBasicBlock(llvm::BasicBlock &BB);
@@ -977,8 +977,34 @@ private:
char IntrinsicsOpt::ID = 0;
IntrinsicsOpt::IntrinsicsOpt()
: BasicBlockPass(ID) {
/** Given an llvm::Value, return true if we can determine that it's an
undefined value. This only makes a weak attempt at chasing this down,
only detecting flat-out undef values, and bitcasts of undef values.
@todo Is it worth working harder to find more of these? It starts to
get tricky, since having an undef operand doesn't necessarily mean that
the result will be undefined. (And for that matter, is there an LLVM
call that will do this for us?)
*/
static bool
lIsUndef(llvm::Value *value) {
if (llvm::isa<llvm::UndefValue>(value))
return true;
llvm::BitCastInst *bci = llvm::dyn_cast<llvm::BitCastInst>(value);
if (bci)
return lIsUndef(bci->getOperand(0));
return false;
}
bool
IntrinsicsOpt::runOnBasicBlock(llvm::BasicBlock &bb) {
DEBUG_START_PASS("IntrinsicsOpt");
// We cant initialize mask/blend function vector during pass initialization,
// as they may be optimized out by the time the pass is invoked.
// All of the mask instructions we may encounter. Note that even if
// compiling for AVX, we may still encounter the regular 4-wide SSE
@@ -1007,34 +1033,6 @@ IntrinsicsOpt::IntrinsicsOpt()
blendInstructions.push_back(BlendInstruction(
m->module->getFunction(llvm::Intrinsic::getName(llvm::Intrinsic::x86_avx_blendv_ps_256)),
0xff, 0, 1, 2));
}
/** Given an llvm::Value, return true if we can determine that it's an
undefined value. This only makes a weak attempt at chasing this down,
only detecting flat-out undef values, and bitcasts of undef values.
@todo Is it worth working harder to find more of these? It starts to
get tricky, since having an undef operand doesn't necessarily mean that
the result will be undefined. (And for that matter, is there an LLVM
call that will do this for us?)
*/
static bool
lIsUndef(llvm::Value *value) {
if (llvm::isa<llvm::UndefValue>(value))
return true;
llvm::BitCastInst *bci = llvm::dyn_cast<llvm::BitCastInst>(value);
if (bci)
return lIsUndef(bci->getOperand(0));
return false;
}
bool
IntrinsicsOpt::runOnBasicBlock(llvm::BasicBlock &bb) {
DEBUG_START_PASS("IntrinsicsOpt");
llvm::Function *avxMaskedLoad32 =
m->module->getFunction(llvm::Intrinsic::getName(llvm::Intrinsic::x86_avx_maskload_ps_256));