-
Notifications
You must be signed in to change notification settings - Fork 12k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
[SDAG] Miscompile of logical or of comparisons of loads with !range metadata #64589
Comments
Candidate patch: https://reviews.llvm.org/D157685 |
/cherry-pick 9deee6b |
Failed to cherry-pick: 9deee6b https://github.com/llvm/llvm-project/actions/runs/5852955782 Please manually backport the fix and push it to your github fork. Once this is done, please add a comment like this:
|
/branch llvm/llvm-project-release-prs/issue64589 |
D141386 changed the semantics of !range metadata to return poison on violation. If !range is combined with !noundef, violation is immediate UB instead, matching the old semantics. In theory, these IR semantics should also carry over into SDAG. In practice, DAGCombine has at least one key transform that is invalid in the presence of poison, namely the conversion of logical and/or to bitwise and/or (https://github.com/llvm/llvm-project/blob/c7b537bf0923df05254f9fa4722b298eb8f4790d/llvm/lib/CodeGen/SelectionDAG/DAGCombiner.cpp#L11252). Ideally, we would fix this transform, but this will require substantial work to avoid codegen regressions. In the meantime, avoid transferring !range metadata without !noundef, effectively restoring the old !range metadata semantics on the SDAG layer. Fixes llvm/llvm-project#64589. Differential Revision: https://reviews.llvm.org/D157685 (cherry picked from commit 9deee6b)
/pull-request llvm/llvm-project-release-prs#580 |
D141386 changed the semantics of !range metadata to return poison on violation. If !range is combined with !noundef, violation is immediate UB instead, matching the old semantics. In theory, these IR semantics should also carry over into SDAG. In practice, DAGCombine has at least one key transform that is invalid in the presence of poison, namely the conversion of logical and/or to bitwise and/or (https://github.com/llvm/llvm-project/blob/c7b537bf0923df05254f9fa4722b298eb8f4790d/llvm/lib/CodeGen/SelectionDAG/DAGCombiner.cpp#L11252). Ideally, we would fix this transform, but this will require substantial work to avoid codegen regressions. In the meantime, avoid transferring !range metadata without !noundef, effectively restoring the old !range metadata semantics on the SDAG layer. Fixes llvm/llvm-project#64589. Differential Revision: https://reviews.llvm.org/D157685 (cherry picked from commit 9deee6b)
Lowers to:
This is incorrect because the
%v2
only has!range
, but not!noundef
. As such, the load may return a poison value.I believe nominally the folds at https://github.com/llvm/llvm-project/blob/68744ffbdd7daac41da274eef9ac0d191e11c16d/llvm/lib/CodeGen/SelectionDAG/DAGCombiner.cpp#L11252 are at fault here: These
select
toand
/or
folds are well-known to be unsound in the presence of poison values.However, removing these folds would be quite involved (as we have seen on the IR side), so the immediate fix here is probably to not transfer
!range
metadata to SDAG if it does not have!noundef
, which sidesteps the issue.The text was updated successfully, but these errors were encountered: