Skip to content

Commit 416f6af

Browse files
committed
AMDGPU: Remove special case folding of fma/mad
These just get replaced with an intrinsic now. This was also introducing host dependence on the result since it relied on the compiler choice to contract or not.
1 parent 0eabe65 commit 416f6af

File tree

1 file changed

+8
-32
lines changed

1 file changed

+8
-32
lines changed

llvm/lib/Target/AMDGPU/AMDGPULibCalls.cpp

Lines changed: 8 additions & 32 deletions
Original file line numberDiff line numberDiff line change
@@ -75,8 +75,8 @@ class AMDGPULibCalls {
7575
bool sincosUseNative(CallInst *aCI, const FuncInfo &FInfo);
7676

7777
// evaluate calls if calls' arguments are constants.
78-
bool evaluateScalarMathFunc(const FuncInfo &FInfo, double& Res0,
79-
double& Res1, Constant *copr0, Constant *copr1, Constant *copr2);
78+
bool evaluateScalarMathFunc(const FuncInfo &FInfo, double &Res0, double &Res1,
79+
Constant *copr0, Constant *copr1);
8080
bool evaluateCall(CallInst *aCI, const FuncInfo &FInfo);
8181

8282
// sqrt
@@ -1306,17 +1306,15 @@ bool AMDGPULibCalls::fold_sincos(FPMathOperator *FPOp, IRBuilder<> &B,
13061306
return true;
13071307
}
13081308

1309-
bool AMDGPULibCalls::evaluateScalarMathFunc(const FuncInfo &FInfo,
1310-
double& Res0, double& Res1,
1311-
Constant *copr0, Constant *copr1,
1312-
Constant *copr2) {
1309+
bool AMDGPULibCalls::evaluateScalarMathFunc(const FuncInfo &FInfo, double &Res0,
1310+
double &Res1, Constant *copr0,
1311+
Constant *copr1) {
13131312
// By default, opr0/opr1/opr3 holds values of float/double type.
13141313
// If they are not float/double, each function has to its
13151314
// operand separately.
1316-
double opr0=0.0, opr1=0.0, opr2=0.0;
1315+
double opr0 = 0.0, opr1 = 0.0;
13171316
ConstantFP *fpopr0 = dyn_cast_or_null<ConstantFP>(copr0);
13181317
ConstantFP *fpopr1 = dyn_cast_or_null<ConstantFP>(copr1);
1319-
ConstantFP *fpopr2 = dyn_cast_or_null<ConstantFP>(copr2);
13201318
if (fpopr0) {
13211319
opr0 = (getArgType(FInfo) == AMDGPULibFunc::F64)
13221320
? fpopr0->getValueAPF().convertToDouble()
@@ -1329,12 +1327,6 @@ bool AMDGPULibCalls::evaluateScalarMathFunc(const FuncInfo &FInfo,
13291327
: (double)fpopr1->getValueAPF().convertToFloat();
13301328
}
13311329

1332-
if (fpopr2) {
1333-
opr2 = (getArgType(FInfo) == AMDGPULibFunc::F64)
1334-
? fpopr2->getValueAPF().convertToDouble()
1335-
: (double)fpopr2->getValueAPF().convertToFloat();
1336-
}
1337-
13381330
switch (FInfo.getId()) {
13391331
default : return false;
13401332

@@ -1486,12 +1478,6 @@ bool AMDGPULibCalls::evaluateScalarMathFunc(const FuncInfo &FInfo,
14861478
Res0 = sin(opr0);
14871479
Res1 = cos(opr0);
14881480
return true;
1489-
1490-
// three-arg functions
1491-
case AMDGPULibFunc::EI_FMA:
1492-
case AMDGPULibFunc::EI_MAD:
1493-
Res0 = opr0 * opr1 + opr2;
1494-
return true;
14951481
}
14961482

14971483
return false;
@@ -1504,7 +1490,6 @@ bool AMDGPULibCalls::evaluateCall(CallInst *aCI, const FuncInfo &FInfo) {
15041490

15051491
Constant *copr0 = nullptr;
15061492
Constant *copr1 = nullptr;
1507-
Constant *copr2 = nullptr;
15081493
if (numArgs > 0) {
15091494
if ((copr0 = dyn_cast<Constant>(aCI->getArgOperand(0))) == nullptr)
15101495
return false;
@@ -1517,32 +1502,23 @@ bool AMDGPULibCalls::evaluateCall(CallInst *aCI, const FuncInfo &FInfo) {
15171502
}
15181503
}
15191504

1520-
if (numArgs > 2) {
1521-
if ((copr2 = dyn_cast<Constant>(aCI->getArgOperand(2))) == nullptr)
1522-
return false;
1523-
}
1524-
15251505
// At this point, all arguments to aCI are constants.
15261506

15271507
// max vector size is 16, and sincos will generate two results.
15281508
double DVal0[16], DVal1[16];
15291509
int FuncVecSize = getVecSize(FInfo);
15301510
bool hasTwoResults = (FInfo.getId() == AMDGPULibFunc::EI_SINCOS);
15311511
if (FuncVecSize == 1) {
1532-
if (!evaluateScalarMathFunc(FInfo, DVal0[0],
1533-
DVal1[0], copr0, copr1, copr2)) {
1512+
if (!evaluateScalarMathFunc(FInfo, DVal0[0], DVal1[0], copr0, copr1)) {
15341513
return false;
15351514
}
15361515
} else {
15371516
ConstantDataVector *CDV0 = dyn_cast_or_null<ConstantDataVector>(copr0);
15381517
ConstantDataVector *CDV1 = dyn_cast_or_null<ConstantDataVector>(copr1);
1539-
ConstantDataVector *CDV2 = dyn_cast_or_null<ConstantDataVector>(copr2);
15401518
for (int i = 0; i < FuncVecSize; ++i) {
15411519
Constant *celt0 = CDV0 ? CDV0->getElementAsConstant(i) : nullptr;
15421520
Constant *celt1 = CDV1 ? CDV1->getElementAsConstant(i) : nullptr;
1543-
Constant *celt2 = CDV2 ? CDV2->getElementAsConstant(i) : nullptr;
1544-
if (!evaluateScalarMathFunc(FInfo, DVal0[i],
1545-
DVal1[i], celt0, celt1, celt2)) {
1521+
if (!evaluateScalarMathFunc(FInfo, DVal0[i], DVal1[i], celt0, celt1)) {
15461522
return false;
15471523
}
15481524
}

0 commit comments

Comments
 (0)