Bug 105139 - [12 Regression] GCC produces vmovw instruction with an incorrect argument for -O3 -march=sapphirerapids since r12-6215-g708b87dcb6e48cb4
Summary: [12 Regression] GCC produces vmovw instruction with an incorrect argument for...
Status: RESOLVED FIXED
Alias: None
Product: gcc
Classification: Unclassified
Component: target (show other bugs)
Version: 12.0
: P3 normal
Target Milestone: 12.0
Assignee: Uroš Bizjak
URL:
Keywords: assemble-failure, wrong-code
Depends on:
Blocks: yarpgen
  Show dependency treegraph
 
Reported: 2022-04-02 18:43 UTC by Vsevolod Livinskii
Modified: 2022-11-29 16:45 UTC (History)
4 users (show)

See Also:
Host:
Target: x86_64-*-*
Build:
Known to work: 11.0
Known to fail:
Last reconfirmed: 2022-04-04 00:00:00


Attachments

Note You need to log in before you can comment on or make changes to this bug.
Description Vsevolod Livinskii 2022-04-02 18:43:50 UTC
Link to the Compiler Explorer: https://godbolt.org/z/9GTPqWfn8

It looks like GCC produced vmovw instruction with an incorrect argument (https://software.intel.com/content/www/us/en/develop/download/intel-avx512-fp16-architecture-specification.html)

Reproducer:
extern long c[];
extern int d[];
long a;
long e(long f) { return f < a ? f : a; }
void g() {
  for (signed b = 0; b < 4028643; b++)
    d[b] = e((char)(~c[b]));
}

Error:
>$ g++ -O3 -march=sapphirerapids -c func.cpp
/tmp/ccB2zLYr.s: Assembler messages:
/tmp/ccB2zLYr.s:92: Error: operand type mismatch for `vmovw'

gcc version 12.0.1 20220401 (git://gcc.gnu.org/git/gcc.git:master 15d683d4f0b390b27c54a7c92c6e4f33195bdc93)

P.S. I'm not sure if "tree-optimization" is the correct classification for this fault
Comment 1 Richard Biener 2022-04-04 07:23:00 UTC
it works for me, it produces

        vmovw   %xmm0, %xmm1

what assembler version are you using?  I have 2.37
Comment 2 Martin Liška 2022-04-04 09:12:12 UTC
It's rejected with 2.38:

$ as -v --64 -o a-pr105139.o a-pr105139.s
GNU assembler version 2.38 (x86_64-suse-linux) using BFD version (GNU Binutils; openSUSE Tumbleweed) 2.38.20220304-3
a-pr105139.s: Assembler messages:
a-pr105139.s:92: Error: operand type mismatch for `vmovw'

Let me bisect GAS.
Comment 3 Martin Liška 2022-04-04 09:25:58 UTC
@Richi: Are you sure about that your GAS supports that?

$ cat vmovw.s
vmovw	%xmm0, %xmm1
$ as -v --64 vmovw.s
GNU assembler version 2.38 (x86_64-suse-linux) using BFD version (GNU Binutils; openSUSE Tumbleweed) 2.38.20220304-3
vmovw.s: Assembler messages:
vmovw.s:1: Error: operand type mismatch for `vmovw'

$ ./gas/as-new /home/marxin/Programming/testcases/vmovw.s -v
GNU assembler version 2.37 (x86_64-pc-linux-gnu) using BFD version (GNU Binutils) 2.37
/home/marxin/Programming/testcases/vmovw.s: Assembler messages:
/home/marxin/Programming/testcases/vmovw.s:1: Error: no such instruction: `vmovw %xmm0,%xmm1'
Comment 4 Martin Liška 2022-04-04 09:27:38 UTC
Started with r12-6215-g708b87dcb6e48cb4.
Comment 5 Richard Biener 2022-04-04 10:52:18 UTC
(In reply to Martin Liška from comment #3)
> @Richi: Are you sure about that your GAS supports that?
> 
> $ cat vmovw.s
> vmovw	%xmm0, %xmm1
> $ as -v --64 vmovw.s
> GNU assembler version 2.38 (x86_64-suse-linux) using BFD version (GNU
> Binutils; openSUSE Tumbleweed) 2.38.20220304-3
> vmovw.s: Assembler messages:
> vmovw.s:1: Error: operand type mismatch for `vmovw'
> 
> $ ./gas/as-new /home/marxin/Programming/testcases/vmovw.s -v
> GNU assembler version 2.37 (x86_64-pc-linux-gnu) using BFD version (GNU
> Binutils) 2.37
> /home/marxin/Programming/testcases/vmovw.s: Assembler messages:
> /home/marxin/Programming/testcases/vmovw.s:1: Error: no such instruction:
> `vmovw %xmm0,%xmm1'

oops, I forgot to actually assemble the output
Comment 6 Uroš Bizjak 2022-04-04 11:58:36 UTC
*movv2qi_internal was not fixed in the same way as *movhi_internal, so:

diff --git a/gcc/config/i386/mmx.md b/gcc/config/i386/mmx.md
index 29d470bdef2..197f19e4b1a 100644
--- a/gcc/config/i386/mmx.md
+++ b/gcc/config/i386/mmx.md
@@ -462,7 +462,7 @@
                    (const_string "TI"))
            (eq_attr "alternative" "5")
              (cond [(match_test "TARGET_AVX512FP16")
-                      (const_string "HI")
+                      (const_string "HF")
                     (match_test "TARGET_AVX")
                       (const_string "TI")
                     (ior (not (match_test "TARGET_SSE2"))
Comment 7 GCC Commits 2022-04-05 19:04:24 UTC
The master branch has been updated by Uros Bizjak <uros@gcc.gnu.org>:

https://gcc.gnu.org/g:cbc9dd66484a51d450f78ab748a872b939c90c3f

commit r12-8004-gcbc9dd66484a51d450f78ab748a872b939c90c3f
Author: Uros Bizjak <ubizjak@gmail.com>
Date:   Tue Apr 5 21:03:18 2022 +0200

    i386: Fix movv2qi_internal xmm reg to xmm reg move for AVX512FP16 [PR105139]
    
    2022-04-05  Uroš Bizjak  <ubizjak@gmail.com>
    
    gcc/ChangeLog:
    
            PR target/105139
            * config/i386/mmx.md (*movv2qi_internal):
            Change insn mode of alternative 5 to HF for TARGET_AVX512FP16.
    
    gcc/testsuite/ChangeLog:
    
            PR target/105139
            * gcc.target/i386/pr105139.c: New test.
Comment 8 Uroš Bizjak 2022-04-05 19:07:18 UTC
Fixed.