Skip to content

Commit fdff191

Browse files
authored
[Hexagon] Use fast-math flags (#162274)
Use fast-math flag `afn` for `fmul` and remove UseUnsafeMath feature, users now should use fast-math flags only, `unsafe-fp-math` attribute support will be removed in future. Hopefully `afn` is the right option This is the Hexagon part.
1 parent 443d027 commit fdff191

File tree

5 files changed

+8
-19
lines changed

5 files changed

+8
-19
lines changed

llvm/lib/Target/Hexagon/Hexagon.td

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -110,8 +110,6 @@ def FeatureSmallData: SubtargetFeature<"small-data", "UseSmallData", "true",
110110
"Allow GP-relative addressing of global variables">;
111111
def FeatureDuplex: SubtargetFeature<"duplex", "EnableDuplex", "true",
112112
"Enable generation of duplex instruction">;
113-
def FeatureUnsafeFP: SubtargetFeature<"unsafe-fp", "UseUnsafeMath", "true",
114-
"Use unsafe FP math">;
115113
def FeatureReservedR19: SubtargetFeature<"reserved-r19", "ReservedR19",
116114
"true", "Reserve register R19">;
117115
def FeatureNoreturnStackElim: SubtargetFeature<"noreturn-stack-elim",
@@ -167,7 +165,6 @@ def UseHVXQFloat : Predicate<"HST->useHVXQFloatOps()">,
167165
def UseHVXFloatingPoint: Predicate<"HST->useHVXFloatingPoint()">;
168166
def HasMemNoShuf : Predicate<"HST->hasMemNoShuf()">,
169167
AssemblerPredicate<(all_of FeatureMemNoShuf)>;
170-
def UseUnsafeMath : Predicate<"HST->useUnsafeMath()">;
171168
def NotOptTinyCore : Predicate<"!HST->isTinyCore() ||"
172169
"MF->getFunction().hasOptSize()"> {
173170
let RecomputePerFunction = 1;

llvm/lib/Target/Hexagon/HexagonPatterns.td

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1611,8 +1611,11 @@ def DfMpy: OutPatFrag<(ops node:$Rs, node:$Rt),
16111611
$Rt, $Rs),
16121612
$Rs, $Rt)>;
16131613

1614-
let Predicates = [HasV67,UseUnsafeMath], AddedComplexity = 50 in {
1615-
def: Pat<(fmul F64:$Rs, F64:$Rt), (DfMpy $Rs, $Rt)>;
1614+
def fmul_afn : PatFrag<(ops node:$a, node:$b), (fmul node:$a, node:$b), [{
1615+
return N->getFlags().hasApproximateFuncs();
1616+
}]>;
1617+
let Predicates = [HasV67], AddedComplexity = 50 in {
1618+
def : Pat<(fmul_afn F64:$Rs, F64:$Rt), (DfMpy $Rs, $Rt)>;
16161619
}
16171620
let Predicates = [HasV67] in {
16181621
def: OpR_RR_pat<F2_dfmin, pf2<fminimumnum>, f64, F64>;

llvm/lib/Target/Hexagon/HexagonSubtarget.h

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -54,7 +54,6 @@ class HexagonSubtarget : public HexagonGenSubtargetInfo {
5454
bool UseNewValueJumps = false;
5555
bool UseNewValueStores = false;
5656
bool UseSmallData = false;
57-
bool UseUnsafeMath = false;
5857
bool UseZRegOps = false;
5958
bool UseHVXIEEEFPOps = false;
6059
bool UseHVXQFloatOps = false;
@@ -234,7 +233,6 @@ class HexagonSubtarget : public HexagonGenSubtargetInfo {
234233
bool useNewValueJumps() const { return UseNewValueJumps; }
235234
bool useNewValueStores() const { return UseNewValueStores; }
236235
bool useSmallData() const { return UseSmallData; }
237-
bool useUnsafeMath() const { return UseUnsafeMath; }
238236
bool useZRegOps() const { return UseZRegOps; }
239237
bool useCabac() const { return UseCabac; }
240238

llvm/lib/Target/Hexagon/HexagonTargetMachine.cpp

Lines changed: 0 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -250,13 +250,6 @@ HexagonTargetMachine::getSubtargetImpl(const Function &F) const {
250250
CPUAttr.isValid() ? CPUAttr.getValueAsString().str() : TargetCPU;
251251
std::string FS =
252252
FSAttr.isValid() ? FSAttr.getValueAsString().str() : TargetFS;
253-
// Append the preexisting target features last, so that +mattr overrides
254-
// the "unsafe-fp-math" function attribute.
255-
// Creating a separate target feature is not strictly necessary, it only
256-
// exists to make "unsafe-fp-math" force creating a new subtarget.
257-
258-
if (F.getFnAttribute("unsafe-fp-math").getValueAsBool())
259-
FS = FS.empty() ? "+unsafe-fp" : "+unsafe-fp," + FS;
260253

261254
auto &I = SubtargetMap[CPU + FS];
262255
if (!I) {

llvm/test/CodeGen/Hexagon/fmul-v67.ll

Lines changed: 3 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,7 @@ b2:
2929
; CHECK: [[R22]] += dfmpylh([[R20]],[[R21]])
3030
; CHECK: [[R22]] += dfmpylh([[R21]],[[R20]])
3131
; CHECK: [[R22]] += dfmpyhh([[R20]],[[R21]])
32-
define double @test_02(double %a0, double %a1) #2 {
32+
define double @test_02(double %a0, double %a1) #1 {
3333
b2:
3434
%v3 = fmul double %a0, %a1
3535
ret double %v3
@@ -40,13 +40,11 @@ b2:
4040
; CHECK: [[R30]] += dfmpylh(r1:0,r3:2)
4141
; CHECK: [[R30]] += dfmpylh(r3:2,r1:0)
4242
; CHECK: [[R30]] += dfmpyhh(r1:0,r3:2)
43-
define double @test_03(double %a0, double %a1) #3 {
43+
define double @test_03(double %a0, double %a1) #1 {
4444
b2:
45-
%v3 = fmul double %a0, %a1
45+
%v3 = fmul afn double %a0, %a1
4646
ret double %v3
4747
}
4848

4949
attributes #0 = { nounwind }
5050
attributes #1 = { nounwind "target-cpu"="hexagonv67" }
51-
attributes #2 = { nounwind "target-cpu"="hexagonv67" "unsafe-fp-math"="false" }
52-
attributes #3 = { nounwind "target-cpu"="hexagonv67" "unsafe-fp-math"="true" }

0 commit comments

Comments
 (0)