[llvm] 3e7ca5f - [SDAG] Read-only intrinsics must have WillReturn and !Throws attributes to be treated as loads (#99999)

via llvm-commits llvm-commits at lists.llvm.org
Fri Aug 16 11:49:00 PDT 2024


Author: Kevin McAfee
Date: 2024-08-16T11:48:57-07:00
New Revision: 3e7ca5f1efabb488663caec371e408d74c634d84

URL: https://github.com/llvm/llvm-project/commit/3e7ca5f1efabb488663caec371e408d74c634d84
DIFF: https://github.com/llvm/llvm-project/commit/3e7ca5f1efabb488663caec371e408d74c634d84.diff

LOG: [SDAG] Read-only intrinsics must have WillReturn and !Throws attributes to be treated as loads (#99999)

This change avoids deleting `!willReturn` intrinsics for which the
return value is unused when building the SDAG. Currently, calls to
read-only intrinsics not marked with `IntrWillReturn` cannot be deleted
at the LLVM IR level but may be deleted when building the SDAG. 
These calls are unsafe to remove from the IR because the functions are
`!willReturn` and should also be unsafe to remove fromthe SDAG for
the same reason. This change aligns the behavior of the SDAG to that
of LLVM IR. This change also requires that intrinsics not have the
`Throws` attribute to be treated as loads for the same reason.

Added: 
    

Modified: 
    llvm/lib/CodeGen/SelectionDAG/SelectionDAGBuilder.cpp

Removed: 
    


################################################################################
diff  --git a/llvm/lib/CodeGen/SelectionDAG/SelectionDAGBuilder.cpp b/llvm/lib/CodeGen/SelectionDAG/SelectionDAGBuilder.cpp
index 8e24f5bd75ec8..87f6b4388a728 100644
--- a/llvm/lib/CodeGen/SelectionDAG/SelectionDAGBuilder.cpp
+++ b/llvm/lib/CodeGen/SelectionDAG/SelectionDAGBuilder.cpp
@@ -5229,7 +5229,8 @@ 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() && F->willReturn() && F->doesNotThrow();
 
   // Build the operand list.
   SmallVector<SDValue, 8> Ops;


        


More information about the llvm-commits mailing list