Skip to content

Commit 594a89f

Browse files
[FPEnv][ARM] Don't call mutateStrictFPToFP when lowering
mutateStrictFPToFP can delete the node and replace it with another with the same value which can later cause problems, and returning the result of mutateStrictFPToFP doesn't work because SelectionDAGLegalize expects that the returned value has the same number of results as the original. Instead handle things by doing the mutation manually. Differential Revision: https://reviews.llvm.org/D74726
1 parent 3eaa53e commit 594a89f

File tree

2 files changed

+55
-2
lines changed

2 files changed

+55
-2
lines changed

llvm/lib/Target/ARM/ARMISelLowering.cpp

Lines changed: 10 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -5425,7 +5425,12 @@ SDValue ARMTargetLowering::LowerFP_TO_INT(SDValue Op, SelectionDAG &DAG) const {
54255425

54265426
// FIXME: Remove this when we have strict fp instruction selection patterns
54275427
if (IsStrict) {
5428-
DAG.mutateStrictFPToFP(Op.getNode());
5428+
SDLoc Loc(Op);
5429+
SDValue Result =
5430+
DAG.getNode(Op.getOpcode() == ISD::STRICT_FP_TO_SINT ? ISD::FP_TO_SINT
5431+
: ISD::FP_TO_UINT,
5432+
Loc, Op.getValueType(), SrcVal);
5433+
return DAG.getMergeValues({Result, Op.getOperand(0)}, Loc);
54295434
}
54305435

54315436
return Op;
@@ -16532,7 +16537,10 @@ SDValue ARMTargetLowering::LowerFP_EXTEND(SDValue Op, SelectionDAG &DAG) const {
1653216537
if (SrcSz == 32 && DstSz == 64 && Subtarget->hasFP64()) {
1653316538
// FIXME: Remove this when we have strict fp instruction selection patterns
1653416539
if (IsStrict) {
16535-
DAG.mutateStrictFPToFP(Op.getNode());
16540+
SDLoc Loc(Op);
16541+
SDValue Result = DAG.getNode(ISD::FP_EXTEND,
16542+
Loc, Op.getValueType(), SrcVal);
16543+
return DAG.getMergeValues({Result, Op.getOperand(0)}, Loc);
1653616544
}
1653716545
return Op;
1653816546
}

llvm/test/CodeGen/ARM/fp-intrinsics.ll

Lines changed: 45 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -72,6 +72,21 @@ define i32 @fptosi_f32(float %x) #0 {
7272
ret i32 %val
7373
}
7474

75+
; CHECK-LABEL: fptosi_f32_twice:
76+
; CHECK-NOSP: bl __aeabi_f2iz
77+
; CHECK-NOSP: bl __aeabi_f2iz
78+
; CHECK-SP: vcvt.s32.f32
79+
; FIXME-CHECK-SP: vcvt.s32.f32
80+
define void @fptosi_f32_twice(float %arg, i32* %ptr) #0 {
81+
entry:
82+
%conv = call i32 @llvm.experimental.constrained.fptosi.f32(float %arg, metadata !"fpexcept.strict") #0
83+
store i32 %conv, i32* %ptr, align 4
84+
%conv1 = call i32 @llvm.experimental.constrained.fptosi.f32(float %arg, metadata !"fpexcept.strict") #0
85+
%idx = getelementptr inbounds i32, i32* %ptr, i32 1
86+
store i32 %conv1, i32* %idx, align 4
87+
ret void
88+
}
89+
7590
; CHECK-LABEL: fptoui_f32:
7691
; CHECK-NOSP: bl __aeabi_f2uiz
7792
; FIXME-CHECK-SP: vcvt.u32.f32
@@ -80,6 +95,21 @@ define i32 @fptoui_f32(float %x) #0 {
8095
ret i32 %val
8196
}
8297

98+
; CHECK-LABEL: fptoui_f32_twice:
99+
; CHECK-NOSP: bl __aeabi_f2uiz
100+
; CHECK-NOSP: bl __aeabi_f2uiz
101+
; FIXME-CHECK-SP: vcvt.u32.f32
102+
; FIXME-CHECK-SP: vcvt.u32.f32
103+
define void @fptoui_f32_twice(float %arg, i32* %ptr) #0 {
104+
entry:
105+
%conv = call i32 @llvm.experimental.constrained.fptoui.f32(float %arg, metadata !"fpexcept.strict") #0
106+
store i32 %conv, i32* %ptr, align 4
107+
%conv1 = call i32 @llvm.experimental.constrained.fptoui.f32(float %arg, metadata !"fpexcept.strict") #0
108+
%idx = getelementptr inbounds i32, i32* %ptr, i32 1
109+
store i32 %conv1, i32* %idx, align 4
110+
ret void
111+
}
112+
83113
; CHECK-LABEL: sqrt_f32:
84114
; CHECK-NOSP: bl sqrtf
85115
; CHECK-SP: vsqrt.f32
@@ -947,6 +977,21 @@ define double @fpext_f32(float %x) #0 {
947977
ret double %val
948978
}
949979

980+
; CHECK-LABEL: fpext_f32_twice:
981+
; CHECK-NODP: bl __aeabi_f2d
982+
; CHECK-NODP: bl __aeabi_f2d
983+
; CHECK-DP: vcvt.f64.f32
984+
; FIXME-CHECK-DP: vcvt.f64.f32
985+
define void @fpext_f32_twice(float %arg, double* %ptr) #0 {
986+
entry:
987+
%conv1 = call double @llvm.experimental.constrained.fpext.f64.f32(float %arg, metadata !"fpexcept.strict") #0
988+
store double %conv1, double* %ptr, align 8
989+
%conv2 = call double @llvm.experimental.constrained.fpext.f64.f32(float %arg, metadata !"fpexcept.strict") #0
990+
%idx = getelementptr inbounds double, double* %ptr, i32 1
991+
store double %conv2, double* %idx, align 8
992+
ret void
993+
}
994+
950995
; CHECK-LABEL: sitofp_f32_i32:
951996
; CHECK-NOSP: bl __aeabi_i2f
952997
; FIXME-CHECK-SP: vcvt.f32.s32

0 commit comments

Comments
 (0)