Message ID | 477d4e63-b313-788d-4b02-1d1750af72f1@linux.ibm.com |
---|---|
State | New |
Headers | show |
Series | [rs6000,PR92379] fix UB shift of 64-bit type by 64 bits | expand |
diff --git a/gcc/config/rs6000/rs6000.c b/gcc/config/rs6000/rs6000.c index 24598aff663..5798f924472 100644 --- a/gcc/config/rs6000/rs6000.c +++ b/gcc/config/rs6000/rs6000.c @@ -5612,7 +5612,10 @@ num_insns_constant_multi (HOST_WIDE_INT value, machine_mode mode) && rs6000_is_valid_and_mask (GEN_INT (low), DImode)) insns = 2; total += insns; - value >>= BITS_PER_WORD; + /* If BITS_PER_WORD is the number of bits in HOST_WIDE_INT, doing + it all at once would be UB. */ + value >>= (BITS_PER_WORD - 1); + value >>= 1; } return total;