]> git.ipfire.org Git - thirdparty/gcc.git/commitdiff
Fix issue with x86_64_const_vector_operand predicate on x86.
authorRoger Sayle <roger@nextmovesoftware.com>
Mon, 18 Jul 2022 06:41:36 +0000 (07:41 +0100)
committerRoger Sayle <roger@nextmovesoftware.com>
Mon, 18 Jul 2022 06:41:36 +0000 (07:41 +0100)
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.

2022-07-18  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.

gcc/config/i386/predicates.md

index c71c453cceb740c26b7fe956bb314be1cad24e14..42053ea7209f66e1ba6cd23ac618fae61fde3663 100644 (file)
 (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);