Attempt to fix infinite loop miscompilation from LLVM side #73561
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
This works by marking all function calls as
mayHaveSideEffects
in LLVM, preventing it from deleting a call to non-halting function. Although it looks simple, this does fix all repros I could run from #28728.It seems LLVM does not delete a loop just because it's not making progress (see this comment). However, LLVM can delete a call to a function containing that loop. This patch prevents the latter.
This has several advantages over #59546:
@llvm.sideeffect
seems difficult to use efficiently. I observed significant slowdown even when combining@llvm.sideeffect
after every function inline, loop unroll, and block merge. Take this with a grain of salt since I'm not an expert of LLVM internals.Submitting here because the LLVM folks already said they don't want this semantic. I'm not sure what the procedure for changing LLVM code is, so please let me know if I'm doing it wrong.