[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
Mon Jul 22 14:47:51 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:

The point of the `willReturn` check is to avoid deleting a `!willReturn` intrinsic. In their non-updated form, the nvvm intrinsics demonstrate the problem of not checking for `willReturn` - the calls are not deleted at the LLVM IR level but are deleted when building the SDAG. This seems incorrect. These calls were unsafe to remove from the IR because the functions are `!willReturn` and should be unsafe to remove from the SDAG for the same reason.

Since these nvvm intrinsics are just loads they should actually be removable, so we update them with `IntrWillReturn`. I don't have an example of a public intrinsic that is intended to behave the same way these intrinsics did before updating them, but it should be possible to make one and keep it from being removed by being `!willReturn`.

That being said, I will remove the SDAG change from this patch and make another PR for that.

https://github.com/llvm/llvm-project/pull/98968


More information about the llvm-commits mailing list