Skip to content

Commit f636e9f

Browse files
john-brawn-armzmodem
authored andcommitted
[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 (cherry picked from commit 594a89f)
1 parent b5d9a7e commit f636e9f

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
@@ -5421,7 +5421,12 @@ SDValue ARMTargetLowering::LowerFP_TO_INT(SDValue Op, SelectionDAG &DAG) const {
54215421

54225422
// FIXME: Remove this when we have strict fp instruction selection patterns
54235423
if (IsStrict) {
5424-
DAG.mutateStrictFPToFP(Op.getNode());
5424+
SDLoc Loc(Op);
5425+
SDValue Result =
5426+
DAG.getNode(Op.getOpcode() == ISD::STRICT_FP_TO_SINT ? ISD::FP_TO_SINT
5427+
: ISD::FP_TO_UINT,
5428+
Loc, Op.getValueType(), SrcVal);
5429+
return DAG.getMergeValues({Result, Op.getOperand(0)}, Loc);
54255430
}
54265431

54275432
return Op;
@@ -16384,7 +16389,10 @@ SDValue ARMTargetLowering::LowerFP_EXTEND(SDValue Op, SelectionDAG &DAG) const {
1638416389
if (SrcSz == 32 && DstSz == 64 && Subtarget->hasFP64()) {
1638516390
// FIXME: Remove this when we have strict fp instruction selection patterns
1638616391
if (IsStrict) {
16387-
DAG.mutateStrictFPToFP(Op.getNode());
16392+
SDLoc Loc(Op);
16393+
SDValue Result = DAG.getNode(ISD::FP_EXTEND,
16394+
Loc, Op.getValueType(), SrcVal);
16395+
return DAG.getMergeValues({Result, Op.getOperand(0)}, Loc);
1638816396
}
1638916397
return Op;
1639016398
}

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)