[llvm] [IndVars] Teach widenLoopCompare to use sext if narrow IV is positive and other operand is already sext. (PR #142703)
Philip Reames via llvm-commits
llvm-commits at lists.llvm.org
Mon Jun 9 08:18:07 PDT 2025
================
@@ -1630,6 +1630,12 @@ bool WidenIV::widenLoopCompare(WidenIV::NarrowIVDefUse DU) {
// Widen the other operand of the compare, if necessary.
if (CastWidth < IVWidth) {
+ // If the narrow IV is always postive and the other operand is sext, widen
----------------
preames wrote:
The bit about not supporting the signed comparison was my key concern. I was going to reason through the unsigned variants, but the alive2 proof nicely does that. Can we add an assert here which checks the no-signed condition precondition?
@dtcxzyw - Your proof really makes me think we should have a instcombine transform which catches this form. Recognizing the icmp zext nonneg, zext (sext) form and replacing the two extends with one seems like a generally useful transform isn't it?
https://github.com/llvm/llvm-project/pull/142703
More information about the llvm-commits
mailing list