[PATCH] D107148: [InstCombine] Fold two-value clamp patterns

Roman Lebedev via Phabricator via llvm-commits llvm-commits at lists.llvm.org
Fri Jul 30 04:50:04 PDT 2021


lebedev.ri added a comment.

In D107148#2916097 <https://reviews.llvm.org/D107148#2916097>, @mkazantsev wrote:

> The initial code
>
>   // s1 = (n < C1) ? n : C1
>   // s2 = (s1 > C1 - 1) ? s1 : C1 - 1
>
> had a clear semantics of
>
>   s1 = min(n, C1)
>   s2 = max(s1, C1 - 1)
>
> These pattern could be analyzed by other passes that understand semantics of min and max, such as SCEV using passes. If it participates in other min or max expression, there is a lot of ways how we can simplify it.
>
> This new form, despite it has fewer instructions, is completely arcane. Just looking at it, it's not so easy to understand what it actually means. And no pass will.
>
> I'd rather suggest to do changes like this as close to codegen as possible, for example in CodeGenPrepare.

Sounds like SCEV should be aware of this way to parse such a select-of-constants as min-max.



================
Comment at: llvm/lib/Transforms/InstCombine/InstCombineSelect.cpp:3102
+    // into:
+    // s2 = C1 - 1 + (n > C1 - 1)
+    CmpInst::Predicate InnerPred;
----------------
I think you should just produce select of constants here.


Repository:
  rG LLVM Github Monorepo

CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D107148/new/

https://reviews.llvm.org/D107148



More information about the llvm-commits mailing list