[Bug tree-optimization/98956] Failure to optimize out boolean left shift

navidrahimi at microsoft dot com gcc-bugzilla@gcc.gnu.org
Wed Nov 17 04:59:41 GMT 2021


https://gcc.gnu.org/bugzilla/show_bug.cgi?id=98956

Navid Rahimi <navidrahimi at microsoft dot com> changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
                 CC|                            |navidrahimi at microsoft dot com

--- Comment #3 from Navid Rahimi <navidrahimi at microsoft dot com> ---
I am sending a patch for this:

/* cmp : ==, != */
/* ((B0 << CST) cmp 0) -> B0 cmp 0 */
(for cmp (eq ne)
 (simplify
  (cmp (lshift (convert @0) INTEGER_CST@1) integer_zerop@2)
  (if (TREE_CODE (TREE_TYPE (@0)) == BOOLEAN_TYPE) (cmp @0 @2))))


This does not apply to other arithmetic operations (at least it is not
verifiable). and for cases that it does apply to other arithmetic operators,
GCC already produces optimized code. You can play with the codegen I link
below:

Codegen:
https://compiler-explorer.com/z/nj4PTrecW

Proof:
https://alive2.llvm.org/ce/z/jyJAoS


More information about the Gcc-bugs mailing list