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

--- Comment #2 from Andrew Pinski <pinskia at gcc dot gnu.org> ---
This produces better gimple:
```
/* (zero_one == 0) ? y : z <op> y -> ((typeof(y))zero_one * z) <op> y */
(for op (bit_xor bit_ior plus)
 (simplify
  (cond (eq zero_one_valued_p@0
            integer_zerop)
        @1
        (op:c @2 @1))
  (if (INTEGRAL_TYPE_P (type)
       && TYPE_PRECISION (type) > 1
       && (INTEGRAL_TYPE_P (TREE_TYPE (@0))))
       (op (mult (bit_and (convert:type @0) { build_one_cst(type); }) @2)
@1))))

/* (zero_one != 0) ? z <op> y : y -> ((typeof(y))zero_one * z) <op> y */
(for op (bit_xor bit_ior plus)
 (simplify
  (cond (ne zero_one_valued_p@0
            integer_zerop)
       (op:c @2 @1)
        @1)
  (if (INTEGRAL_TYPE_P (type)
       && TYPE_PRECISION (type) > 1
       && (INTEGRAL_TYPE_P (TREE_TYPE (@0))))
       (op (mult (bit_and (convert:type @0) { build_one_cst(type); }) @2)
@1))))
```
But it still has extra gimple produced for unsigned 1 bit field:
```
Folded into the sequence:
_7 = (int) _1;
_8 = (int) _1;
_9 = b_5(D) * _8;
_10 = a_4(D) | _9;
statement un-sinked:
a_6 = a_4(D) | b_5(D);
Removing basic block 3
;; basic block 3, loop depth 0
;;  pred:       2
;;  succ:       4


Removing dead stmt:a_6 = a_4(D) | b_5(D);
Removing dead stmt:_7 = (int) _1;
```
Maybe that is ok.

For signed 1-bit this is produced:
```
Folded into the sequence:
_7 = (int) _1;
_8 = _7 & 1;
_9 = b_5(D) * _8;
_10 = a_4(D) | _9;
statement un-sinked:
a_6 = a_4(D) | b_5(D);
Removing basic block 3
;; basic block 3, loop depth 0
;;  pred:       2
;;  succ:       4


Removing dead stmt:a_6 = a_4(D) | b_5(D);
```

I think this is the best I am going to get it.

Reply via email to