AVX512: fmsub intrinsic generates fmadd instruction
| Bugzilla Link | 28892 |
| Resolution | FIXED |
| Resolved on | Sep 07, 2016 09:47 |
| Version | trunk |
| OS | All |
| CC | @delena,@hfinkel |
Extended Description
Consider the following simple snippet which uses the fused multiply subtract instruction on AVX512 and AVX:
=============
#include <immintrin.h>
__m512 test(__m512 a, __m512 b, __m512 c) { return _mm512_fmsub_ps(a, b, c); }
__m256 test(__m256 a, __m256 b, __m256 c) { return _mm256_fmsub_ps(a, b, c); }
=============
In the AVX512 case, LLVM trunk generates the following weird code which does a sign flip first followed by a FMADD instruction. The AVX backend, in comparison, generates the expected (single FMADD instruction).
_Z4testDv16_fS_S: vpxord LCPI0_0(%rip), %zmm2, %zmm2 vfmadd213ps %zmm2, %zmm1, %zmm0 retq
_Z4testDv8_fS_S: vfmsub213ps %ymm2, %ymm1, %ymm0 retq
Confirmed, that fixes it -- thank you!
Should look better after r280785. Please check.
I submitted an additional patch https://reviews.llvm.org/D24221 for review.
Assembly output is:
_Z4testDv16_fS_S: ## @Z4testDv16_fS_S .cfi_startproc
BB#0:
pushq %rbp
Ltmp0: .cfi_def_cfa_offset 16 Ltmp1: .cfi_offset %rbp, -16 movq %rsp, %rbp Ltmp2: .cfi_def_cfa_register %rbp vbroadcastss LCPI0_0(%rip), %zmm3 vpxorq %zmm3, %zmm2, %zmm2 vfmadd213ps %zmm2, %zmm1, %zmm0 popq %rbp retq .cfi_endproc
I still observe this issue for the provided source code file (llvm/trunk 280458).
Compilation flags:
$ bin/clang++ test.cpp -o test.s -S -O3 -mavx512f -mfma
fixed in 280368
Great, thank you -- I look forward to having this fixed.
I submitted a patch that fixes this https://reviews.llvm.org/D23313, but guys disagree with me. I assume they are right and I'll try to find another solution. I was on vacation for 2 weeks, now I'm coming back and this bug is in my stack.
Any thought about this issue? I just checked, and it is still present on the latest version of Clang.