[llvm] Check for side effects when lowering target intrinsics, update NVVM ldu/ldg intrinsics with IntrWillReturn and test for DCE (PR #98968)
Kevin McAfee via llvm-commits
llvm-commits at lists.llvm.org
Tue Jul 16 13:51:05 PDT 2024
================
@@ -5227,7 +5227,7 @@ void SelectionDAGBuilder::visitTargetIntrinsic(const CallInst &I,
// definition.
const Function *F = I.getCalledFunction();
bool HasChain = !F->doesNotAccessMemory();
- bool OnlyLoad = HasChain && F->onlyReadsMemory();
+ bool OnlyLoad = HasChain && F->onlyReadsMemory() && !I.mayHaveSideEffects();
----------------
kalxr wrote:
Thanks for explaining!
> The code previously only considers the attributes of the underlying function definition, which is what all other intrinsic code expects (and changes the opcode between INTRINSIC_WO_CHAIN/INTRINSIC_W_CHAIN/INTRINSIC_VOID). This now will swap the opcode and operand structure depending on whether the callsite has a memory(none) attribute.
I understand that it will affect the operands, but I don't see where `OnlyLoad` affects the opcode. That seems like something determined by `HasChain`.
> ... you can only consider the underlying function declaration and not the instruction / call site instance
If the issue is with using the instruction, would it then be reasonable to use `F->willReturn()` instead of `!I.mayHaveSideEffects()`? It still appears to me incorrect to treat an intrinsic as only a load when it may not return, as the previous code is doing.
https://github.com/llvm/llvm-project/pull/98968
More information about the llvm-commits
mailing list