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

Richard Earnshaw <rearnsha at gcc dot gnu.org> changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
         Resolution|DUPLICATE                   |FIXED

--- Comment #8 from Richard Earnshaw <rearnsha at gcc dot gnu.org> ---
(In reply to Andrew Pinski from comment #5)
> From fold-const.cc:
> ```
>       /* Canonicalize (X & C1) | C2.  */
> ...
>           /* Minimize the number of bits set in C1, i.e. C1 := C1 & ~C2,
>              unless (C1 & ~C2) | (C2 & C3) for some C3 is a mask of some
>              mode which allows further optimizations.  */
>           c1 &= msk;
>           c2 &= msk;
>           wide_int c3 = wi::bit_and_not (c1, c2);
>           for (w = BITS_PER_UNIT; w <= width; w <<= 1)
>             {
>               wide_int mask = wi::mask (w, false,
>                                         TYPE_PRECISION (type));
>               if (((c1 | c2) & mask) == mask
>                   && wi::bit_and_not (c1, mask) == 0)
>                 {
>                   c3 = mask;
>                   break;
>                 }
>             }
> 
>           if (c3 != c1)
>             {
>               tem = fold_convert_loc (loc, type, TREE_OPERAND (arg0, 0));
>               tem = fold_build2_loc (loc, BIT_AND_EXPR, type, tem,
>                                      wide_int_to_tree (type, c3));
>               return fold_build2_loc (loc, BIT_IOR_EXPR, type, tem, arg1);
>             }
> ```

Rather than minimizing the number of bits set, it would probably be better to
find a constant with the smallest magnitude.  On RISC targets that would
probably lead to a smaller number of insns, while on CISC targets it would lead
to a shorter instruction (assuming it can load arbitrary constants in a single
insn).

Reply via email to