From: Jakub Jelinek <[email protected]>

I believe we never have LROTATE_EXPRs/RROTATE_EXPRs with signed large/huge
_BitInt operands in the IL, because the forwprop pattern matching doesn't
try to match those (because we know they will be split again) and while
__builtin_stdc_rotate_* emits them, it is only for unsigned operands.
That said, in the lowering I actually attempted to write support for
those, just made two errors in there if the operand is not INTEGER_CST.
One is creating a cast from the signed type to the signed type again
instead of its unsigned variant, and the other is not actually using
the result of the cast later on.

The following patch fixes both of those.

2026-10-19  Jakub Jelinek  <[email protected]>

        PR middle-end/127921
        * gimple-lower-bitint.cc (gimple_lower_bitint) <case LROTATE_EXPR>:
        Fix up cast to utype if rhs1 is not INTEGER_CST.

Reviewed-by: Richard Biener <[email protected]>
---
 gcc/gimple-lower-bitint.cc | 3 ++-
 1 file changed, 2 insertions(+), 1 deletion(-)

diff --git a/gcc/gimple-lower-bitint.cc b/gcc/gimple-lower-bitint.cc
index 9b52dab2f9cac..5d844d2a95617 100644
--- a/gcc/gimple-lower-bitint.cc
+++ b/gcc/gimple-lower-bitint.cc
@@ -7490,10 +7490,11 @@ gimple_lower_bitint (void)
                        rhs1 = fold_convert (utype, rhs1);
                      else
                        {
-                         tree t = make_ssa_name (type);
+                         tree t = make_ssa_name (utype);
                          g = gimple_build_assign (t, NOP_EXPR, rhs1);
                          gsi_insert_before (&gsi, g, GSI_SAME_STMT);
                          gimple_set_location (g, loc);
+                         rhs1 = t;
                        }
                    }
                  g = gimple_build_assign (make_ssa_name (TREE_TYPE (rhs1)),
-- 
2.54.0

Reply via email to