https://gcc.gnu.org/bugzilla/show_bug.cgi?id=114801

--- Comment #15 from Jakub Jelinek <jakub at gcc dot gnu.org> ---
https://developer.arm.com/documentation/101028/0012/14--M-profile-Vector-Extension--MVE--intrinsics
suggests that it is a UB if all the bits for a single element aren't the same
(i.e. false is all 0s, true is all 1s aka -1, anything else UB).
So the testcase is invalid at runtime, right?
It probably shouldn't error because it can be in dead code, and it certainly
shouldn't ICE, it could emit __builtin_trap or it can just canonicalize it any
way it likes it.

Seems you are canonicalizing that to 1s, given the HW behavior I think it would
be more correct to canonicalize to -1s.

I think you could simply canonicalize on the CONST_INT, so
   else if (VALID_MVE_PRED_MODE (mode))
     {
       if (CONST_INT_P (x) && (mode == V8BImode || mode == V4BImode))
         {
           /* In V8BI or V4BI each element has 2 or 4 bits, if those
              bits aren't all the same, it is UB and gen_lowpart might
              ICE.  Canonicalize all the 2 or 4 bits to all ones if
              any of them is non-zero.  */
           unsigned HOST_WIDE_INT xi = UINTVAL (xi);
           xi |= ((xi & 0x5555) << 1) | ((xi & 0xaaaa) >> 1);
           if (mode == V4BImode)
             xi |= ((xi & 0x3333) << 2) | ((xi & 0xcccc) >> 2);
           x = gen_int_mode (xi, HImode);
         }
       else if (SUBREG_P (x))
         /* gen_lowpart on a SUBREG can ICE.  */
         x = force_reg (GET_MODE (x), x);
       x = gen_lowpart (mode, x);
     }

Reply via email to