Skip to content

Commit e88fec7

Browse files
author
Vineet Kumar
committed
[X86][ISel][FMA] Get a handle on operand nodes when negating FMA
When negaitng an FMA opcode, a new node created for a negated FMA operand may be deleted while recursively negating another FMA operand. This commit adds a temporary handle on the new negated nodes to prevent them from being deleted.
1 parent 1b75b9e commit e88fec7

File tree

2 files changed

+30
-0
lines changed

2 files changed

+30
-0
lines changed

llvm/lib/Target/X86/X86ISelLowering.cpp

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -55673,7 +55673,12 @@ static SDValue combineFMA(SDNode *N, SelectionDAG &DAG,
5567355673
// Do not convert the passthru input of scalar intrinsics.
5567455674
// FIXME: We could allow negations of the lower element only.
5567555675
bool NegA = invertIfNegative(A);
55676+
// Create a dummy use for A so that in the process of negating B or C
55677+
// recursively, it is not deleted.
55678+
HandleSDNode NegAHandle(A);
5567655679
bool NegB = invertIfNegative(B);
55680+
// Similar to A, get a handle on B.
55681+
HandleSDNode NegBHandle(B);
5567755682
bool NegC = invertIfNegative(C);
5567855683

5567955684
if (!NegA && !NegB && !NegC)
Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,25 @@
1+
; NOTE: Assertions have been autogenerated by utils/update_llc_test_checks.py UTC_ARGS: --version 5
2+
; RUN: llc < %s -mtriple=x86_64-unknown-linux-gnu -mattr=+avx512f -mattr=+fma | FileCheck %s
3+
4+
define void @fma_neg(<8 x i1> %r280, ptr %pp1, ptr %pp2) {
5+
; CHECK-LABEL: fma_neg:
6+
; CHECK: # %bb.0:
7+
; CHECK-NEXT: vpmovsxwq %xmm0, %zmm0
8+
; CHECK-NEXT: vpsllq $63, %zmm0, %zmm0
9+
; CHECK-NEXT: vptestmq %zmm0, %zmm0, %k1
10+
; CHECK-NEXT: vmovdqu64 (%rdi), %zmm0
11+
; CHECK-NEXT: vpxorq {{\.?LCPI[0-9]+_[0-9]+}}(%rip){1to8}, %zmm0, %zmm1 {%k1} {z}
12+
; CHECK-NEXT: vxorpd %xmm2, %xmm2, %xmm2
13+
; CHECK-NEXT: vfnmadd213pd {{.*#+}} zmm2 = -(zmm0 * zmm2) + zmm1
14+
; CHECK-NEXT: vmovupd %zmm2, (%rsi)
15+
; CHECK-NEXT: vzeroupper
16+
; CHECK-NEXT: retq
17+
%r290 = load <8 x double>, ptr %pp1, align 8
18+
%r307 = fneg <8 x double> %r290
19+
%r309 = select <8 x i1> %r280, <8 x double> %r307, <8 x double> zeroinitializer
20+
%r311 = tail call <8 x double> @llvm.x86.avx512.vfmadd.pd.512(<8 x double> %r307, <8 x double> zeroinitializer, <8 x double> %r309, i32 4)
21+
store <8 x double> %r311, ptr %pp2, align 8
22+
ret void
23+
}
24+
25+
declare <8 x double> @llvm.x86.avx512.vfmadd.pd.512(<8 x double>, <8 x double>, <8 x double>, i32 immarg)

0 commit comments

Comments
 (0)