@@ -11611,7 +11611,13 @@ fold_binary_loc (location_t loc,
if (integer_pow2p (sval) && tree_int_cst_sgn (sval) > 0)
{
tree sh_cnt = TREE_OPERAND (arg1, 1);
- unsigned long pow2 = exact_log2 (TREE_INT_CST_LOW (sval));
+ unsigned long pow2;
+
+ if (TREE_INT_CST_LOW (sval))
+ pow2 = exact_log2 (TREE_INT_CST_LOW (sval));
+ else
+ pow2 = exact_log2 (TREE_INT_CST_HIGH (sval))
+ + HOST_BITS_PER_WIDE_INT;
if (strict_overflow_p)
fold_overflow_warning (("assuming signed overflow does not "
@@ -0,0 +1,14 @@
+/* PR middle-end/46019 */
+
+extern void abort (void);
+
+int
+main (void)
+{
+ unsigned long long l = 0x40000000000ULL;
+ int n;
+ for (n = 0; n < 8; n++)
+ if (l / (0x200000000ULL << n) != (0x200 >> n))
+ abort ();
+ return 0;
+}