[llvm] Simplify `(a % b) lt/ge (b-1)` into `(a % b) eq/ne (b-1)` (PR #72504)

Nikita Popov via llvm-commits llvm-commits at lists.llvm.org
Mon Nov 20 08:57:16 PST 2023


nikic wrote:

I think the most principled way to handle this would be to generalize the existing handling for converting inequality to equality comparisons which currently only uses dominating conditions to also use computeConstantRange(). I've sketched this out here: https://github.com/llvm/llvm-project/commit/541ec50dd7907e0945f30fd3778d599425a4e665

This does cause quite a few regressions that would have to be fixed first.

It also regresses compile-time: http://llvm-compile-time-tracker.com/compare.php?from=9ca9c2cf7e05a0fe44a8a688d0c322d5229511d9&to=541ec50dd7907e0945f30fd3778d599425a4e665&stat=instructions%3Au

Possibly the compile-time regression can be avoided if we support ConstantRange in WithCache, because we already perform this computeConstantRange() call in InstSimplify.

In the meantime adding srem specific handling sounds okay, but I'm not willing to accept support for non-constant operands.

https://github.com/llvm/llvm-project/pull/72504


More information about the llvm-commits mailing list