Skip to content

Commit f97f964

Browse files
authored
[GlobalISel][ARM] Legalize reset_fpmode (#115859)
Implement lowering intrinsic `reset_fpmode` in Global Selector for ARM target.
1 parent b69f646 commit f97f964

File tree

2 files changed

+29
-0
lines changed

2 files changed

+29
-0
lines changed

llvm/lib/Target/ARM/ARMLegalizerInfo.cpp

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -163,6 +163,7 @@ ARMLegalizerInfo::ARMLegalizerInfo(const ARMSubtarget &ST) : ST(ST) {
163163
.legalFor({s32});
164164
getActionDefinitionsBuilder(G_RESET_FPENV).alwaysLegal();
165165
getActionDefinitionsBuilder(G_SET_FPMODE).customFor({s32});
166+
getActionDefinitionsBuilder(G_RESET_FPMODE).custom();
166167
} else {
167168
getActionDefinitionsBuilder({G_FADD, G_FSUB, G_FMUL, G_FDIV})
168169
.libcallFor({s32, s64});
@@ -467,6 +468,17 @@ bool ARMLegalizerInfo::legalizeCustom(LegalizerHelper &Helper, MachineInstr &MI,
467468
MIRBuilder.buildSetFPEnv(NewFPSCR);
468469
break;
469470
}
471+
case G_RESET_FPMODE: {
472+
// To get the default FP mode all control bits are cleared:
473+
// FPSCR = FPSCR & (FPStatusBits | FPReservedBits)
474+
LLT FPEnvTy = LLT::scalar(32);
475+
auto FPEnv = MIRBuilder.buildGetFPEnv(FPEnvTy);
476+
auto NotModeBitMask = MIRBuilder.buildConstant(
477+
FPEnvTy, ARM::FPStatusBits | ARM::FPReservedBits);
478+
auto NewFPSCR = MIRBuilder.buildAnd(FPEnvTy, FPEnv, NotModeBitMask);
479+
MIRBuilder.buildSetFPEnv(NewFPSCR);
480+
break;
481+
}
470482
}
471483

472484
MI.eraseFromParent();

llvm/test/CodeGen/ARM/GlobalISel/fpenv.ll

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -165,5 +165,22 @@ entry:
165165
ret void
166166
}
167167

168+
define void @reset_fpmode() nounwind {
169+
; CHECK-LABEL: reset_fpmode:
170+
; CHECK: @ %bb.0: @ %entry
171+
; CHECK-NEXT: vmrs r0, fpscr
172+
; CHECK-NEXT: ldr r1, .LCPI11_0
173+
; CHECK-NEXT: and r0, r0, r1
174+
; CHECK-NEXT: vmsr fpscr, r0
175+
; CHECK-NEXT: mov pc, lr
176+
; CHECK-NEXT: .p2align 2
177+
; CHECK-NEXT: @ %bb.1:
178+
; CHECK-NEXT: .LCPI11_0:
179+
; CHECK-NEXT: .long 4160774399 @ 0xf80060ff
180+
entry:
181+
call void @llvm.reset.fpmode()
182+
ret void
183+
}
184+
168185
attributes #0 = { nounwind "use-soft-float"="true" }
169186

0 commit comments

Comments
 (0)