[llvm] [SCEVExpander] Support hoisting udiv X, Y where Y is non-zero (PR #96102)
Philip Reames via llvm-commits
llvm-commits at lists.llvm.org
Mon Jun 24 08:46:18 PDT 2024
================
@@ -1470,12 +1470,11 @@ Value *SCEVExpander::expand(const SCEV *S) {
// We can move insertion point only if there is no div or rem operations
// otherwise we are risky to move it over the check for zero denominator.
- auto SafeToHoist = [](const SCEV *S) {
- return !SCEVExprContains(S, [](const SCEV *S) {
+ auto SafeToHoist = [&](const SCEV *S) {
+ return !SCEVExprContains(S, [&](const SCEV *S) {
if (const auto *D = dyn_cast<SCEVUDivExpr>(S)) {
- if (const auto *SC = dyn_cast<SCEVConstant>(D->getRHS()))
- // Division by non-zero constants can be hoisted.
- return SC->getValue()->isZero();
+ if (SE.isKnownNonZero(D->getRHS()))
----------------
preames wrote:
That is a great question. I think we do. We don't in a whole bunch of other cases, so this bug is not unique my new code, but yeah, I don't see any reason why hosting "udiv X, poison" above control flow would be legal.
https://github.com/llvm/llvm-project/pull/96102
More information about the llvm-commits
mailing list