diff options
author | Yingwei Zheng <dtcxzyw2333@gmail.com> | 2025-04-11 09:03:06 +0800 |
---|---|---|
committer | GitHub <noreply@github.com> | 2025-04-11 09:03:06 +0800 |
commit | d14acb78065bdd331019924feaaef52e5e744529 (patch) | |
tree | 7e2d906e867c2c8313a949436dec5018f7558452 /llvm/lib/Transforms/Utils/SimplifyIndVar.cpp | |
parent | 77db154cf9383fa20685fca56633601ce0ea47fa (diff) | |
download | llvm-d14acb78065bdd331019924feaaef52e5e744529.zip llvm-d14acb78065bdd331019924feaaef52e5e744529.tar.gz llvm-d14acb78065bdd331019924feaaef52e5e744529.tar.bz2 |
[IndVarSimplify] Handle the case where both operands are the same when widening IV (#135207)
`WidenIV::widenWithVariantUse` assumes that exactly one of the binop
operands is the IV to be widened. This miscompilation happens when it
tries to sign-extend the "NonIV" operand while the IV is zero-extended.
Closes https://github.com/llvm/llvm-project/issues/135182.
Diffstat (limited to 'llvm/lib/Transforms/Utils/SimplifyIndVar.cpp')
-rw-r--r-- | llvm/lib/Transforms/Utils/SimplifyIndVar.cpp | 3 |
1 files changed, 3 insertions, 0 deletions
diff --git a/llvm/lib/Transforms/Utils/SimplifyIndVar.cpp b/llvm/lib/Transforms/Utils/SimplifyIndVar.cpp index 7b9c5c7..5a76bec 100644 --- a/llvm/lib/Transforms/Utils/SimplifyIndVar.cpp +++ b/llvm/lib/Transforms/Utils/SimplifyIndVar.cpp @@ -1743,6 +1743,9 @@ bool WidenIV::widenWithVariantUse(WidenIV::NarrowIVDefUse DU) { // TODO: Support case for NarrowDef = NarrowUse->getOperand(1). if (NarrowUse->getOperand(0) != NarrowDef) return false; + // We cannot use a different extend kind for the same operand. + if (NarrowUse->getOperand(1) == NarrowDef) + return false; if (!SE->isKnownNegative(RHS)) return false; bool ProvedSubNUW = SE->isKnownPredicateAt(ICmpInst::ICMP_UGE, LHS, |