]> git.ipfire.org Git - thirdparty/gcc.git/commitdiff
vect: Fix integer overflow calculating mask
authorAndrew Stubbs <ams@baylibre.com>
Thu, 22 Feb 2024 15:41:00 +0000 (15:41 +0000)
committerAndrew Stubbs <ams@baylibre.com>
Mon, 4 Mar 2024 15:39:02 +0000 (15:39 +0000)
The masks and bitvectors were broken when nunits==32 on hosts where int is
32-bit.

gcc/ChangeLog:

* dojump.cc (do_compare_and_jump): Use full-width integers for shifts.
* expr.cc (store_constructor): Likewise.
(do_store_flag): Likewise.

gcc/dojump.cc
gcc/expr.cc

index ac744e54cf89cf38e6b527ef84da19dc7c458e8c..88600cb42d3d0abfc4c56b8a8a33d734d4f3a585 100644 (file)
@@ -1318,10 +1318,10 @@ do_compare_and_jump (tree treeop0, tree treeop1, enum rtx_code signed_code,
     {
       gcc_assert (code == EQ || code == NE);
       op0 = expand_binop (mode, and_optab, op0,
-                         GEN_INT ((1 << nunits) - 1), NULL_RTX,
+                         GEN_INT ((HOST_WIDE_INT_1U << nunits) - 1), NULL_RTX,
                          true, OPTAB_WIDEN);
       op1 = expand_binop (mode, and_optab, op1,
-                         GEN_INT ((1 << nunits) - 1), NULL_RTX,
+                         GEN_INT ((HOST_WIDE_INT_1U << nunits) - 1), NULL_RTX,
                          true, OPTAB_WIDEN);
     }
 
index 8d34d024c9c1248cb36bbfd78f90e9514cee513e..f7d74525c15be76567bb5b084d387f33c216b2cb 100644 (file)
@@ -7879,8 +7879,8 @@ store_constructor (tree exp, rtx target, int cleared, poly_int64 size,
            auto nunits = TYPE_VECTOR_SUBPARTS (type).to_constant ();
            if (maybe_ne (GET_MODE_PRECISION (mode), nunits))
              tmp = expand_binop (mode, and_optab, tmp,
-                                 GEN_INT ((1 << nunits) - 1), target,
-                                 true, OPTAB_WIDEN);
+                                 GEN_INT ((HOST_WIDE_INT_1U << nunits) - 1),
+                                 target, true, OPTAB_WIDEN);
            if (tmp != target)
              emit_move_insn (target, tmp);
            break;
@@ -13707,11 +13707,11 @@ do_store_flag (sepops ops, rtx target, machine_mode mode)
     {
       gcc_assert (code == EQ || code == NE);
       op0 = expand_binop (mode, and_optab, op0,
-                         GEN_INT ((1 << nunits) - 1), NULL_RTX,
-                         true, OPTAB_WIDEN);
+                         GEN_INT ((HOST_WIDE_INT_1U << nunits) - 1),
+                         NULL_RTX, true, OPTAB_WIDEN);
       op1 = expand_binop (mode, and_optab, op1,
-                         GEN_INT ((1 << nunits) - 1), NULL_RTX,
-                         true, OPTAB_WIDEN);
+                         GEN_INT ((HOST_WIDE_INT_1U << nunits) - 1),
+                         NULL_RTX, true, OPTAB_WIDEN);
     }
 
   if (target == 0)