Skip to content

Commit ccfa525

Browse files
committed
[X86] Make sure we don't combine (fneg (fma X, Y, Z)) to a target specific node when there are no FMA instructions.
This would cause a 'cannot select' error at isel when we should have emitted a lib call and an xor. Fixes PR36553. llvm-svn: 326393
1 parent 75c649c commit ccfa525

File tree

2 files changed

+21
-1
lines changed

2 files changed

+21
-1
lines changed

llvm/lib/Target/X86/X86ISelLowering.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -35737,7 +35737,7 @@ static SDValue combineFneg(SDNode *N, SelectionDAG &DAG,
3573735737
// If we're negating an FMA node, then we can adjust the
3573835738
// instruction to include the extra negation.
3573935739
unsigned NewOpcode = 0;
35740-
if (Arg.hasOneUse()) {
35740+
if (Arg.hasOneUse() && Subtarget.hasAnyFMA()) {
3574135741
switch (Arg.getOpcode()) {
3574235742
case ISD::FMA: NewOpcode = X86ISD::FNMSUB; break;
3574335743
case X86ISD::FMSUB: NewOpcode = X86ISD::FNMADD; break;

llvm/test/CodeGen/X86/pr36553.ll

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
; NOTE: Assertions have been autogenerated by utils/update_llc_test_checks.py
2+
; RUN: llc < %s -mtriple=x86_64-apple-darwin10 | FileCheck %s
3+
4+
; Make sure we don't crash because we negated an fma when we didn't have any fma instructions.
5+
6+
define float @pr36553(float %a, float %b, float %c) nounwind {
7+
; CHECK-LABEL: pr36553:
8+
; CHECK: ## %bb.0: ## %entry
9+
; CHECK-NEXT: pushq %rax
10+
; CHECK-NEXT: callq _fmaf
11+
; CHECK-NEXT: xorps {{.*}}(%rip), %xmm0
12+
; CHECK-NEXT: popq %rax
13+
; CHECK-NEXT: retq
14+
entry:
15+
%0 = tail call float @llvm.fma.f32(float %a, float %b, float %c)
16+
%sub = fsub float -0.000000e+00, %0
17+
ret float %sub
18+
}
19+
20+
declare float @llvm.fma.f32(float, float, float)

0 commit comments

Comments
 (0)