From 20482cfcc1d3b71e0aec57b5b48685bf0b5402ca Mon Sep 17 00:00:00 2001 From: Jakub Jelinek Date: Wed, 10 Feb 2021 19:50:11 +0100 Subject: [PATCH] i386: Fix ICEs due to simplify_gen_subreg returning NULL [PR99025] In these patterns, we call simplify_gen_subreg on the input operand to create paradoxical subregs that have 2x, 4x or 8x elements as the input operand. That works fine if the input operand is a REG, but when it is a SUBREG, RTL doesn't allow SUBREG of SUBREG and so relies on simplify_subreg actually simplifying it. And e.g. if the input operand is a SUBREG that changes the element mode (floating vs. non-floating) and then combined with a paradoxical subreg (i.e. different size) this can easily fail, then simplify_gen_subreg returns NULL but we still use it in instructions. Fixed by forcing the operands into REG. 2021-02-10 Jakub Jelinek PR target/99025 * config/i386/sse.md (fix_truncv2sfv2di2, v8qiv8hi2, v8qiv8si2, v4qiv4si2, v4hiv4si2, v8qiv8di2, v4qiv4di2, v2qiv2di2, v4hiv4di2, v2hiv2di2, v2siv2di2): Force operands[1] into REG before calling simplify_gen_subreg on it. * gcc.target/i386/pr99025.c: New test. --- gcc/config/i386/sse.md | 11 +++++++++++ gcc/testsuite/gcc.target/i386/pr99025.c | 17 +++++++++++++++++ 2 files changed, 28 insertions(+) create mode 100644 gcc/testsuite/gcc.target/i386/pr99025.c diff --git a/gcc/config/i386/sse.md b/gcc/config/i386/sse.md index 369a00d8f51..db5be59f5b7 100644 --- a/gcc/config/i386/sse.md +++ b/gcc/config/i386/sse.md @@ -6356,6 +6356,7 @@ (match_operand:V2SF 1 "register_operand")))] "TARGET_AVX512DQ && TARGET_AVX512VL" { + operands[1] = force_reg (V2SFmode, operands[1]); operands[1] = simplify_gen_subreg (V4SFmode, operands[1], V2SFmode, 0); emit_insn (gen_avx512dq_fix_truncv2sfv2di2 (operands[0], operands[1])); @@ -18013,6 +18014,7 @@ { if (!MEM_P (operands[1])) { + operands[1] = force_reg (V8QImode, operands[1]); operands[1] = simplify_gen_subreg (V16QImode, operands[1], V8QImode, 0); emit_insn (gen_sse4_1_v8qiv8hi2 (operands[0], operands[1])); DONE; @@ -18090,6 +18092,7 @@ { if (!MEM_P (operands[1])) { + operands[1] = force_reg (V8QImode, operands[1]); operands[1] = simplify_gen_subreg (V16QImode, operands[1], V8QImode, 0); emit_insn (gen_avx2_v8qiv8si2 (operands[0], operands[1])); DONE; @@ -18153,6 +18156,7 @@ { if (!MEM_P (operands[1])) { + operands[1] = force_reg (V4QImode, operands[1]); operands[1] = simplify_gen_subreg (V16QImode, operands[1], V4QImode, 0); emit_insn (gen_sse4_1_v4qiv4si2 (operands[0], operands[1])); DONE; @@ -18279,6 +18283,7 @@ { if (!MEM_P (operands[1])) { + operands[1] = force_reg (V4HImode, operands[1]); operands[1] = simplify_gen_subreg (V8HImode, operands[1], V4HImode, 0); emit_insn (gen_sse4_1_v4hiv4si2 (operands[0], operands[1])); DONE; @@ -18366,6 +18371,7 @@ { if (!MEM_P (operands[1])) { + operands[1] = force_reg (V8QImode, operands[1]); operands[1] = simplify_gen_subreg (V16QImode, operands[1], V8QImode, 0); emit_insn (gen_avx512f_v8qiv8di2 (operands[0], operands[1])); DONE; @@ -18427,6 +18433,7 @@ { if (!MEM_P (operands[1])) { + operands[1] = force_reg (V8QImode, operands[1]); operands[1] = simplify_gen_subreg (V16QImode, operands[1], V8QImode, 0); emit_insn (gen_avx2_v4qiv4di2 (operands[0], operands[1])); DONE; @@ -18453,6 +18460,7 @@ (match_operand:V2QI 1 "register_operand")))] "TARGET_SSE4_1" { + operands[1] = force_reg (V2QImode, operands[1]); operands[1] = simplify_gen_subreg (V16QImode, operands[1], V2QImode, 0); emit_insn (gen_sse4_1_v2qiv2di2 (operands[0], operands[1])); DONE; @@ -18525,6 +18533,7 @@ { if (!MEM_P (operands[1])) { + operands[1] = force_reg (V4HImode, operands[1]); operands[1] = simplify_gen_subreg (V8HImode, operands[1], V4HImode, 0); emit_insn (gen_avx2_v4hiv4di2 (operands[0], operands[1])); DONE; @@ -18586,6 +18595,7 @@ { if (!MEM_P (operands[1])) { + operands[1] = force_reg (V2HImode, operands[1]); operands[1] = simplify_gen_subreg (V8HImode, operands[1], V2HImode, 0); emit_insn (gen_sse4_1_v2hiv2di2 (operands[0], operands[1])); DONE; @@ -18737,6 +18747,7 @@ { if (!MEM_P (operands[1])) { + operands[1] = force_reg (V2SImode, operands[1]); operands[1] = simplify_gen_subreg (V4SImode, operands[1], V2SImode, 0); emit_insn (gen_sse4_1_v2siv2di2 (operands[0], operands[1])); DONE; diff --git a/gcc/testsuite/gcc.target/i386/pr99025.c b/gcc/testsuite/gcc.target/i386/pr99025.c new file mode 100644 index 00000000000..288538d618a --- /dev/null +++ b/gcc/testsuite/gcc.target/i386/pr99025.c @@ -0,0 +1,17 @@ +/* PR target/99025 */ +/* { dg-do compile } */ +/* { dg-options "-O3 -msse4" } */ + +long v[16]; +int w; +union U { float u; int r; } x; + +void +foo (float y) +{ + union U z; + x.u = w; + v[5] = x.r; + z.u = y; + v[6] = z.r; +} -- 2.30.2