public inbox for gcc-patches@gcc.gnu.org
 help / color / mirror / Atom feed
* [x86 PATCH] Fix issue with x86_64_const_vector_operand predicate.
@ 2022-07-16 12:06 Roger Sayle
  2022-07-18  6:07 ` Uros Bizjak
  0 siblings, 1 reply; 2+ messages in thread
From: Roger Sayle @ 2022-07-16 12:06 UTC (permalink / raw)
  To: 'GCC Patches'

[-- Attachment #1: Type: text/plain, Size: 1470 bytes --]


This patch fixes (what I believe is) a latent bug in i386.md's
x86_64_const_vector_operand define_predicate.  According to the
documentation, when a predicate is called with rtx operand OP and
machine_mode operand MODE, we can't shouldn't assume that the
MODE is (or has been checked to be) GET_MODE (OP).

The failure mode is that recog can call x86_64_const_vector_operand
on an arbitrary CONST_VECTOR passing a MODE of V2QI_mode, but when
the CONST_VECTOR is in fact V1TImode, it's unsafe to directly call
ix86_convert_const_vector_to_integer, which assumes that the CONST_VECTOR
contains CONST_INTs when it actually contains CONST_WIDE_INTs.  The
checks in this define_predicate need to be testing OP's mode, and
ideally confirming that this matches the passed in/specified MODE.

This bug is currently latent, but adding an innocent/unrelated
define_insn, such as "(set (reg:CCC FLAGS_REG) (const_int 0))" to
i386.md can occasionally change the order in which genrecog generates
its tests, then ICEing during bootstrap due to V1TI CONST_VECTORs.


This patch has been tested on x86_64-pc-linux-gnu with make bootstrap
and make -k check, both with and without --target-board=unix{-m32},
with no new failures.  Ok for mainline?

2022-07-16  Roger Sayle  <roger@nextmovesoftware.com>

gcc/ChangeLog
        * config/i386/predicates.md (x86_64_const_vector_operand):
        Check the operand's mode matches the specified mode argument.


Thanks in advance,
Roger
--


[-- Attachment #2: patchpm.txt --]
[-- Type: text/plain, Size: 541 bytes --]

diff --git a/gcc/config/i386/predicates.md b/gcc/config/i386/predicates.md
index c71c453..42053ea 100644
--- a/gcc/config/i386/predicates.md
+++ b/gcc/config/i386/predicates.md
@@ -1199,6 +1199,10 @@
 (define_predicate "x86_64_const_vector_operand"
   (match_code "const_vector")
 {
+  if (mode == VOIDmode)
+    mode = GET_MODE (op);
+  else if (GET_MODE (op) != mode)
+    return false;
   if (GET_MODE_SIZE (mode) > UNITS_PER_WORD)
     return false;
   HOST_WIDE_INT val = ix86_convert_const_vector_to_integer (op, mode);

^ permalink raw reply	[flat|nested] 2+ messages in thread

* Re: [x86 PATCH] Fix issue with x86_64_const_vector_operand predicate.
  2022-07-16 12:06 [x86 PATCH] Fix issue with x86_64_const_vector_operand predicate Roger Sayle
@ 2022-07-18  6:07 ` Uros Bizjak
  0 siblings, 0 replies; 2+ messages in thread
From: Uros Bizjak @ 2022-07-18  6:07 UTC (permalink / raw)
  To: Roger Sayle; +Cc: GCC Patches

On Sat, Jul 16, 2022 at 2:06 PM Roger Sayle <roger@nextmovesoftware.com> wrote:
>
>
> This patch fixes (what I believe is) a latent bug in i386.md's
> x86_64_const_vector_operand define_predicate.  According to the
> documentation, when a predicate is called with rtx operand OP and
> machine_mode operand MODE, we can't shouldn't assume that the
> MODE is (or has been checked to be) GET_MODE (OP).
>
> The failure mode is that recog can call x86_64_const_vector_operand
> on an arbitrary CONST_VECTOR passing a MODE of V2QI_mode, but when
> the CONST_VECTOR is in fact V1TImode, it's unsafe to directly call
> ix86_convert_const_vector_to_integer, which assumes that the CONST_VECTOR
> contains CONST_INTs when it actually contains CONST_WIDE_INTs.  The
> checks in this define_predicate need to be testing OP's mode, and
> ideally confirming that this matches the passed in/specified MODE.
>
> This bug is currently latent, but adding an innocent/unrelated
> define_insn, such as "(set (reg:CCC FLAGS_REG) (const_int 0))" to
> i386.md can occasionally change the order in which genrecog generates
> its tests, then ICEing during bootstrap due to V1TI CONST_VECTORs.
>
>
> This patch has been tested on x86_64-pc-linux-gnu with make bootstrap
> and make -k check, both with and without --target-board=unix{-m32},
> with no new failures.  Ok for mainline?
>
> 2022-07-16  Roger Sayle  <roger@nextmovesoftware.com>
>
> gcc/ChangeLog
>         * config/i386/predicates.md (x86_64_const_vector_operand):
>         Check the operand's mode matches the specified mode argument.

OK.

Thanks,
Uros.

>
>
> Thanks in advance,
> Roger
> --
>

^ permalink raw reply	[flat|nested] 2+ messages in thread

end of thread, other threads:[~2022-07-18  6:07 UTC | newest]

Thread overview: 2+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2022-07-16 12:06 [x86 PATCH] Fix issue with x86_64_const_vector_operand predicate Roger Sayle
2022-07-18  6:07 ` Uros Bizjak

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).