On Wed, Feb 23, 2022 at 11:36:26AM +0100, Richard Biener wrote: > > The following patch avoids infinite recursion during generic folding. > > The (cmp (bswap @0) INTEGER_CST@1) simplification relies on > > (bswap @1) actually being simplified, if it is not simplified, we just > > move the bswap from one operand to the other and if @0 is also INTEGER_CST, > > we apply the same rule next. > > > > The reason why bswap @1 isn't folded to INTEGER_CST is that the INTEGER_CST > > has TREE_OVERFLOW set on it and fold-const-call.cc predicate punts in > > such cases: > > static inline bool > > integer_cst_p (tree t) > > { > > return TREE_CODE (t) == INTEGER_CST && !TREE_OVERFLOW (t); > > } > > The patch uses ! modifier to ensure the bswap is simplified, but because > > ! is only supported in gimple-match, guards it also with #if GIMPLE. > > > > Bootstrapped/regtested on x86_64-linux and i686-linux, ok for trunk? > > Does it recurse on GIMPLE as well? If not, the ! is not necessary > since you guard with GIMPLE already (but it deserves a comment I guess).
It could if TREE_OVERFLOW would somehow appear in there, but given that the gimplifier and other spots drop_tree_overflow, it is only theoretical. Note, I've posted a different version of the patch that allows optimizing this even if GENERIC in most cases. I think I prefer that version. Jakub