]> gcc.gnu.org Git - gcc.git/commit
combine: Fix up expand_compound_operation [PR99905]
authorJakub Jelinek <jakub@redhat.com>
Mon, 12 Apr 2021 23:01:45 +0000 (01:01 +0200)
committerJakub Jelinek <jakub@redhat.com>
Tue, 20 Apr 2021 23:28:20 +0000 (01:28 +0200)
commit00fc4d9fff1f38c205b52e0723eb3b03989ee292
treedddfb69d4c5bbbac3e70ddab94e41da14327b57c
parent6bb1dccf0defbcf245b0804211e20be8624c1f40
combine: Fix up expand_compound_operation [PR99905]

The following testcase is miscompiled on x86_64-linux.
expand_compound_operation is called on
(zero_extract:DI (mem/c:TI (reg/f:DI 16 argp) [3 i+0 S16 A128])
    (const_int 16 [0x10])
    (const_int 63 [0x3f]))
so mode is DImode, inner_mode is TImode, pos 63, len 16 and modewidth 64.

A couple of lines above the problematic spot we have:
  if (modewidth >= pos + len)
    {
      tem = gen_lowpart (mode, XEXP (x, 0));
where the code uses gen_lowpart and then shift left/right to extract it
in mode.  But the guarding condition is false - 64 >= 63 + 16
and so we enter the next condition, where the code shifts XEXP (x, 0)
right by pos and then adds AND.  It does so incorrectly though.
Given the modewidth < pos + len, inner_mode must be necessarily larger
than mode and XEXP (x, 0) has the innermode, but it was calling
simplify_shift_const with mode rather than inner_mode, which meant
inconsistent arguments to simplify_shift_const and in this case made
a DImode MEM shift out of it.

The following patch fixes it, by doing the shift in inner_mode properly
and then after the shift doing the lowpart subreg and masking already
in mode.

2021-04-13  Jakub Jelinek  <jakub@redhat.com>

PR rtl-optimization/99905
* combine.c (expand_compound_operation): If pos + len > modewidth,
perform the right shift by pos in inner_mode and then convert to mode,
instead of trying to simplify a shift of rtx with inner_mode by pos
as if it was a shift in mode.

* gcc.target/i386/pr99905.c: New test.

(cherry picked from commit c965254e5af9dc68444e0289250c393ae0cd6131)
gcc/combine.c
gcc/testsuite/gcc.target/i386/pr99905.c [new file with mode: 0644]
This page took 0.056027 seconds and 5 git commands to generate.