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

Max Kazantsev via Phabricator via llvm-commits llvm-commits at lists.llvm.org
Fri Jul 30 04:42:19 PDT 2021


mkazantsev added a comment.

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.


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