[PATCH] D90231: [GVN] Don't replace argument to @llvm.is.constant.*()

Joerg Sonnenberger via Phabricator via llvm-commits llvm-commits at lists.llvm.org
Thu Oct 29 04:45:57 PDT 2020


joerg added a comment.

"It compiles with GCC" is not really helpful as argument because the observed behavior depends on a lot of internals. It is quite frankly impossible to be 100% identical to GCC's behavior. What LLVM guarantees is:
(1) Folding to false happens as late as reasonable possible. It happens most importantly after the first round of function and loop optimizations.
(2) Folding to true happens as part of constant folding etc as early as the condition is evaluated.
(3) The result is propagated to derived expression and those are folded recursively, including dead code elimination. This happens even for -O0.

That's why `__builtin_constant_p(i)` followed by the range check is fine as far as LLVM is concerned. With -O0, it fails as it doesn't have the help of SROA and the whole code branch is killed. Otherwise, `i` is a known constant and the range check is constant folded. The assembler constraint is verified using the same machinery anyway.


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

https://reviews.llvm.org/D90231



More information about the llvm-commits mailing list