llvm-project icon indicating copy to clipboard operation
llvm-project copied to clipboard

AVX512: fmsub intrinsic generates fmadd instruction

Open wjakob opened this issue 10 years ago • 9 comments

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

wjakob avatar Aug 07 '16 21:08 wjakob

Confirmed, that fixes it -- thank you!

wjakob avatar Sep 07 '16 16:09 wjakob

Should look better after r280785. Please check.

delena avatar Sep 07 '16 16:09 delena

I submitted an additional patch https://reviews.llvm.org/D24221 for review.

delena avatar Sep 04 '16 21:09 delena

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

wjakob avatar Sep 02 '16 12:09 wjakob

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

wjakob avatar Sep 02 '16 12:09 wjakob

fixed in 280368

delena avatar Sep 01 '16 15:09 delena

Great, thank you -- I look forward to having this fixed.

wjakob avatar Aug 30 '16 14:08 wjakob

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.

delena avatar Aug 27 '16 20:08 delena

Any thought about this issue? I just checked, and it is still present on the latest version of Clang.

wjakob avatar Aug 22 '16 21:08 wjakob