diff --git a/llvm/lib/Transforms/Scalar/EarlyCSE.cpp b/llvm/lib/Transforms/Scalar/EarlyCSE.cpp index a1dbb4e1d5e75..cd4846e006031 100644 --- a/llvm/lib/Transforms/Scalar/EarlyCSE.cpp +++ b/llvm/lib/Transforms/Scalar/EarlyCSE.cpp @@ -964,33 +964,26 @@ class EarlyCSE { bool overridingStores(const ParseMemoryInst &Earlier, const ParseMemoryInst &Later); - Value *getOrCreateResult(Value *Inst, Type *ExpectedType) const { - // TODO: We could insert relevant casts on type mismatch here. - if (auto *LI = dyn_cast(Inst)) - return LI->getType() == ExpectedType ? LI : nullptr; - if (auto *SI = dyn_cast(Inst)) { - Value *V = SI->getValueOperand(); - return V->getType() == ExpectedType ? V : nullptr; + Value *getOrCreateResult(Instruction *Inst, Type *ExpectedType) const { + // TODO: We could insert relevant casts on type mismatch. + // The load or the store's first operand. + Value *V; + if (auto *II = dyn_cast(Inst)) { + switch (II->getIntrinsicID()) { + case Intrinsic::masked_load: + V = II; + break; + case Intrinsic::masked_store: + V = II->getOperand(0); + break; + default: + return TTI.getOrCreateResultFromMemIntrinsic(II, ExpectedType); + } + } else { + V = isa(Inst) ? Inst : cast(Inst)->getValueOperand(); } - assert(isa(Inst) && "Instruction not supported"); - auto *II = cast(Inst); - if (isHandledNonTargetIntrinsic(II->getIntrinsicID())) - return getOrCreateResultNonTargetMemIntrinsic(II, ExpectedType); - return TTI.getOrCreateResultFromMemIntrinsic(II, ExpectedType); - } - Value *getOrCreateResultNonTargetMemIntrinsic(IntrinsicInst *II, - Type *ExpectedType) const { - // TODO: We could insert relevant casts on type mismatch here. - switch (II->getIntrinsicID()) { - case Intrinsic::masked_load: - return II->getType() == ExpectedType ? II : nullptr; - case Intrinsic::masked_store: { - Value *V = II->getOperand(0); - return V->getType() == ExpectedType ? V : nullptr; - } - } - return nullptr; + return V->getType() == ExpectedType ? V : nullptr; } /// Return true if the instruction is known to only operate on memory