Skip to content

Commit 3e7ca5f

Browse files
authored
[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.
1 parent 51ede55 commit 3e7ca5f

File tree

1 file changed

+2
-1
lines changed

1 file changed

+2
-1
lines changed

llvm/lib/CodeGen/SelectionDAG/SelectionDAGBuilder.cpp

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5229,7 +5229,8 @@ void SelectionDAGBuilder::visitTargetIntrinsic(const CallInst &I,
52295229
// definition.
52305230
const Function *F = I.getCalledFunction();
52315231
bool HasChain = !F->doesNotAccessMemory();
5232-
bool OnlyLoad = HasChain && F->onlyReadsMemory();
5232+
bool OnlyLoad =
5233+
HasChain && F->onlyReadsMemory() && F->willReturn() && F->doesNotThrow();
52335234

52345235
// Build the operand list.
52355236
SmallVector<SDValue, 8> Ops;

0 commit comments

Comments
 (0)