@@ -16381,31 +16381,56 @@ bool PPCTargetLowering::isFMAFasterThanFMulAndFAdd(const Function &F,
16381
16381
}
16382
16382
}
16383
16383
16384
- // Currently this is a copy from AArch64TargetLowering::isProfitableToHoist.
16385
- // FIXME: add more patterns which are profitable to hoist.
16384
+ // FIXME: add more patterns which are not profitable to hoist.
16386
16385
bool PPCTargetLowering::isProfitableToHoist(Instruction *I) const {
16387
- if (I->getOpcode() != Instruction::FMul)
16388
- return true;
16389
-
16390
16386
if (!I->hasOneUse())
16391
16387
return true;
16392
16388
16393
16389
Instruction *User = I->user_back();
16394
16390
assert(User && "A single use instruction with no uses.");
16395
16391
16396
- if (User->getOpcode() != Instruction::FSub &&
16397
- User->getOpcode() != Instruction::FAdd)
16398
- return true;
16392
+ switch (I->getOpcode()) {
16393
+ case Instruction::FMul: {
16394
+ // Don't break FMA, PowerPC prefers FMA.
16395
+ if (User->getOpcode() != Instruction::FSub &&
16396
+ User->getOpcode() != Instruction::FAdd)
16397
+ return true;
16399
16398
16400
- const TargetOptions &Options = getTargetMachine().Options;
16401
- const Function *F = I->getFunction();
16402
- const DataLayout &DL = F->getParent()->getDataLayout();
16403
- Type *Ty = User->getOperand(0)->getType();
16404
-
16405
- return !(
16406
- isFMAFasterThanFMulAndFAdd(*F, Ty) &&
16407
- isOperationLegalOrCustom(ISD::FMA, getValueType(DL, Ty)) &&
16408
- (Options.AllowFPOpFusion == FPOpFusion::Fast || Options.UnsafeFPMath));
16399
+ const TargetOptions &Options = getTargetMachine().Options;
16400
+ const Function *F = I->getFunction();
16401
+ const DataLayout &DL = F->getParent()->getDataLayout();
16402
+ Type *Ty = User->getOperand(0)->getType();
16403
+
16404
+ return !(
16405
+ isFMAFasterThanFMulAndFAdd(*F, Ty) &&
16406
+ isOperationLegalOrCustom(ISD::FMA, getValueType(DL, Ty)) &&
16407
+ (Options.AllowFPOpFusion == FPOpFusion::Fast || Options.UnsafeFPMath));
16408
+ }
16409
+ case Instruction::Load: {
16410
+ // Don't break "store (load float*)" pattern, this pattern will be combined
16411
+ // to "store (load int32)" in later InstCombine pass. See function
16412
+ // combineLoadToOperationType. On PowerPC, loading a float point takes more
16413
+ // cycles than loading a 32 bit integer.
16414
+ LoadInst *LI = cast<LoadInst>(I);
16415
+ // For the loads that combineLoadToOperationType does nothing, like
16416
+ // ordered load, it should be profitable to hoist them.
16417
+ // For swifterror load, it can only be used for pointer to pointer type, so
16418
+ // later type check should get rid of this case.
16419
+ if (!LI->isUnordered())
16420
+ return true;
16421
+
16422
+ if (User->getOpcode() != Instruction::Store)
16423
+ return true;
16424
+
16425
+ if (I->getType()->getTypeID() != Type::FloatTyID)
16426
+ return true;
16427
+
16428
+ return false;
16429
+ }
16430
+ default:
16431
+ return true;
16432
+ }
16433
+ return true;
16409
16434
}
16410
16435
16411
16436
const MCPhysReg *
0 commit comments