We should not clone stored values unless they are GEPs that are special cased to avoid hoisting them without hoisting their associated ld/st.
Details
Diff Detail
Event Timeline
| llvm/lib/Transforms/Scalar/GVNHoist.cpp | ||
|---|---|---|
| 586–590 | We could put the check here: ...
GetElementPtrInst *Val = nullptr;
if (auto *St = dyn_cast<StoreInst>(Repl)) {
Gep = ...
Val = dyn_cast<GetElementPtrInst>(St->getValueOperand()); | |
| llvm/lib/Transforms/Scalar/GVNHoist.cpp | ||
|---|---|---|
| 586–590 | I think this is not possible: we need to check whether the stored value is available at HoistPt. | |
| llvm/lib/Transforms/Scalar/GVNHoist.cpp | ||
|---|---|---|
| 588 | I think you want "Val && !DT->dominates(Val->getParent(), HoistPt)", or something like that? You care whether the value itself is available, not its operands. | |
| llvm/lib/Transforms/Scalar/GVNHoist.cpp | ||
|---|---|---|
| 588 | This is correct. We do not need to check all operands of the Val instruction. | |
For everything except GEPs, only check that the stored value is available: do not check the availability of the operands.
You're missing an allOperandsAvailable call if Val is a GEP. (I'm not sure why you're even trying to special-case GEPs here.)
I think you want "Val && !DT->dominates(Val->getParent(), HoistPt)", or something like that? You care whether the value itself is available, not its operands.