@@ -12410,7 +12410,8 @@ simplify_comparison (enum rtx_code code,
bit. This will be converted into a ZERO_EXTRACT. */
if (const_op == 0 && sign_bit_comparison_p
&& CONST_INT_P (XEXP (op0, 1))
- && mode_width <= HOST_BITS_PER_WIDE_INT)
+ && mode_width <= HOST_BITS_PER_WIDE_INT
+ && UINTVAL (XEXP (op0, 1)) < mode_width)
{
op0 = simplify_and_const_int (NULL_RTX, mode, XEXP (op0, 0),
(HOST_WIDE_INT_1U
@@ -0,0 +1,15 @@
+/* PR middle-end/93505 */
+
+unsigned a;
+
+unsigned
+foo (unsigned x)
+{
+ unsigned int y = 32 - __builtin_bswap64 (-a);
+ /* This would be UB (x << 32) at runtime. Ensure we don't
+ invoke UB in the compiler because of that (visible with
+ bootstrap-ubsan). */
+ x = x << y | x >> (-y & 31);
+ x >>= 31;
+ return x;
+}