On 23/02/2024 13:02, Jakub Jelinek wrote:
On Fri, Feb 23, 2024 at 12:58:53PM +0000, Andrew Stubbs wrote:
This is a follow-up to the previous patch to ensure that integer vector
bit-masks do not have excess bits set. It fixes a bug, observed on
amdgcn, in which the mask could be incorrectly set to zero, resulting in
wrong-code.

The mask was broken when nunits==32. The patched version will probably
be broken for nunits==64, but I don't think any current targets have
masks with more than 64 bits.

OK for mainline?

Andrew

gcc/ChangeLog:

        * expr.cc (store_constructor): Use 64-bit shifts.

No, this isn't 64-bit shift on all hosts.
Use HOST_WIDE_INT_1U instead.

OK, I did wonder if there was a proper way to do it. :)

How about this?

Andrew
vect: Fix integer overflow calculating mask

The mask was broken when nunits==32 on hosts where int is 32-bit.

gcc/ChangeLog:

        * expr.cc (store_constructor): Use 64-bit shifts.

diff --git a/gcc/expr.cc b/gcc/expr.cc
index e238811110e..6bd16ac7f49 100644
--- a/gcc/expr.cc
+++ b/gcc/expr.cc
@@ -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;

Reply via email to