[all-commits] [llvm/llvm-project] e4d01b: [SCEV] Special case sext in isKnownNonZero (#77834)

Philip Reames via All-commits all-commits at lists.llvm.org
Fri Jan 12 07:45:40 PST 2024


  Branch: refs/heads/main
  Home:   https://github.com/llvm/llvm-project
  Commit: e4d01bb2273804355cf84a8a560e578735590ac2
      https://github.com/llvm/llvm-project/commit/e4d01bb2273804355cf84a8a560e578735590ac2
  Author: Philip Reames <preames at rivosinc.com>
  Date:   2024-01-12 (Fri, 12 Jan 2024)

  Changed paths:
    M llvm/lib/Analysis/ScalarEvolution.cpp
    M llvm/test/CodeGen/PowerPC/loop-instr-form-prepare.ll
    M llvm/test/Transforms/LoopStrengthReduce/lsr-term-fold.ll

  Log Message:
  -----------
  [SCEV] Special case sext in isKnownNonZero (#77834)

The existing logic in isKnownNonZero relies on unsigned ranges, which
can be problematic when our range calculation is imprecise. Consider the
following:
  %offset.nonzero = or i32 %offset, 1
  -->  %offset.nonzero U: [1,0) S: [1,0)
  %offset.i64 = sext i32 %offset.nonzero to i64
  -->  (sext i32 %offset.nonzero to i64) U: [-2147483648,2147483648)
                                         S: [-2147483648,2147483648)

Note that the unsigned range for the sext does contain zero in this case
despite the fact that it can never actually be zero.

Instead, we can push the query down one level - relying on the fact that
the sext is an invertible operation and that the result can only be zero
if the input is. We could likely generalize this reasoning for other
invertible operations, but special casing sext seems worthwhile.




More information about the All-commits mailing list