Bug 24352 - Incorrect EVEX optimization
Summary: Incorrect EVEX optimization
Status: RESOLVED FIXED
Alias: None
Product: binutils
Classification: Unclassified
Component: gas (show other bugs)
Version: 2.33
: P2 normal
Target Milestone: 2.33
Assignee: Not yet assigned to anyone
URL:
Keywords:
Depends on:
Blocks:
 
Reported: 2019-03-16 22:15 UTC by H.J. Lu
Modified: 2020-05-26 17:42 UTC (History)
0 users

See Also:
Host:
Target: i386
Build:
Last reconfirmed:


Attachments

Note You need to log in before you can comment on or make changes to this bug.
Description H.J. Lu 2019-03-16 22:15:35 UTC
[hjl@gnu-gram-1 testsuite]$ cat x.s
	vandnpd %zmm1, %zmm1, %zmm16
	vandnpd %zmm17, %zmm17, %zmm1
[hjl@gnu-gram-1 testsuite]$ as -O2 -o x.o x.s
[hjl@gnu-gram-1 testsuite]$  objdump -dw x.o

x.o:     file format elf64-x86-64


Disassembly of section .text:

0000000000000000 <.text>:
   0:	62 e1 f5 48 55 c1    	vandnpd %zmm1,%zmm1,%zmm16
   6:	62 b1 f5 40 55 c9    	vandnpd %zmm17,%zmm17,%zmm1
[hjl@gnu-gram-1 testsuite]$ 

They should be encoded with 128-bit EVEX.

[hjl@gnu-gram-1 testsuite]$ cat > y.s
vandnpd %ymm1, %ymm1, %ymm15
[hjl@gnu-gram-1 testsuite]$ as -O2 -march=+noavx -o y.o y.s
[hjl@gnu-gram-1 testsuite]$ objdump -dw y.o

y.o:     file format elf64-x86-64


Disassembly of section .text:

0000000000000000 <.text>:
   0:	c5 71 55 f9          	vandnpd %xmm1,%xmm1,%xmm15
[hjl@gnu-gram-1 testsuite]$ 

AVX shouldn't be used when AVX isn't available.
Comment 1 Sourceware Commits 2019-03-16 23:27:29 UTC
The master branch has been updated by H.J. Lu <hjl@sourceware.org>:

https://sourceware.org/git/gitweb.cgi?p=binutils-gdb.git;h=dd22218cf26fa5d8beade7266de391a28e63527b

commit dd22218cf26fa5d8beade7266de391a28e63527b
Author: H.J. Lu <hjl.tools@gmail.com>
Date:   Sun Mar 17 07:25:08 2019 +0800

    x86: Correctly optimize EVEX to 128-bit VEX/EVEX
    
    We can optimize 512-bit EVEX to 128-bit EVEX encoding for upper 16
    vector registers only when AVX512VL is enabled.  We can't optimize
    EVEX to 128-bit VEX encoding when AVX isn't enabled.
    
    	PR gas/24352
    	* config/tc-i386.c (optimize_encoding): Encode 512-bit EVEX
    	with 128-bit VEX encoding only when AVX is enabled and with
    	128-bit EVEX encoding only when AVX512VL is enabled.
    	* testsuite/gas/i386/i386.exp: Run PR gas/24352 tests.
    	* testsuite/gas/i386/optimize-6.s: New file.
    	* testsuite/gas/i386/optimize-6a.d: Likewise.
    	* testsuite/gas/i386/optimize-6b.d: Likewise.
    	* testsuite/gas/i386/optimize-6c.d: Likewise.
    	* testsuite/gas/i386/x86-64-optimize-7.s: Likewise.
    	* testsuite/gas/i386/x86-64-optimize-7a.d: Likewise.
    	* testsuite/gas/i386/x86-64-optimize-7b.d: Likewise.
    	* testsuite/gas/i386/x86-64-optimize-7c.d: Likewise.
    	* testsuite/gas/i386/x86-64-optimize-2.d: Updated.
Comment 2 Sourceware Commits 2019-03-19 13:12:25 UTC
The master branch has been updated by H.J. Lu <hjl@sourceware.org>:

https://sourceware.org/git/gitweb.cgi?p=binutils-gdb.git;h=7b1d7ca194544554f7d41aea7fdf7a69c232f15d

commit 7b1d7ca194544554f7d41aea7fdf7a69c232f15d
Author: H.J. Lu <hjl.tools@gmail.com>
Date:   Tue Mar 19 21:10:21 2019 +0800

    x86: Correct EVEX to 128-bit EVEX optimization
    
    Since not all AVX512F processors support AVX512VL, we can optimize
    512-bit EVEX to 128-bit EVEX encoding for upper 16 vector registers
    only when AVX512VL is enabled explicitly at command-line or via
    ".arch .avx512vl" directive.
    
    	PR gas/24352
    	* config/tc-i386.c (optimize_encoding): Check only
    	cpu_arch_flags.bitfield.cpuavx512vl.
    	* testsuite/gas/i386/i386.exp: Run x86-64-optimize-2b.
    	* testsuite/gas/i386/x86-64-optimize-2.d: Revert the last
    	change.
    	* testsuite/gas/i386/x86-64-optimize-2b.d: New file.
    	* testsuite/gas/i386/x86-64-optimize-2b.s: Likewise.
Comment 3 H.J. Lu 2020-05-26 17:42:19 UTC
Fixed for 2.33.