[llvm] [GVN] Teach GVN simple masked load/store forwarding (PR #157689)
David Sherwood via llvm-commits
llvm-commits at lists.llvm.org
Mon Sep 29 03:27:34 PDT 2025
================
@@ -2287,6 +2287,36 @@ bool GVNPass::processLoad(LoadInst *L) {
return true;
}
+// Attempt to process masked loads which have loaded from
+// masked stores with the same mask
+bool GVNPass::processMaskedLoad(IntrinsicInst *I) {
+ if (!MD)
+ return false;
+ MemDepResult Dep = MD->getDependency(I);
+ Instruction *DepInst = Dep.getInst();
+ if (!DepInst || !Dep.isLocal() || !Dep.isDef())
+ return false;
+
+ Value *Mask = I->getOperand(2);
+ Value *Passthrough = I->getOperand(3);
+ Value *StoreVal;
+ if (!match(DepInst, m_MaskedStore(m_Value(StoreVal), m_Value(), m_Value(),
+ m_Specific(Mask))))
+ return false;
+
+ // Remove the load but generate a select for the passthrough
+ Value *OpToForward = llvm::SelectInst::Create(Mask, StoreVal, Passthrough, "",
+ I->getIterator());
+
+ ICF->removeUsersOf(I);
+ I->replaceAllUsesWith(OpToForward);
+ salvageAndRemoveInstruction(I);
+ if (OpToForward->getType()->isPtrOrPtrVectorTy())
----------------
david-arm wrote:
Do we need a test for this, i.e. loading/storing a vector of pointers?
https://github.com/llvm/llvm-project/pull/157689
More information about the llvm-commits
mailing list