[llvm] e48892e - [Transforms] LICM.cpp - pull out repeated getUserCost call
Simon Pilgrim via llvm-commits
llvm-commits at lists.llvm.org
Thu Aug 18 02:44:04 PDT 2022
Author: Simon Pilgrim
Date: 2022-08-18T10:43:29+01:00
New Revision: e48892ee42304284099a9b25c10d34fdc55a99f7
URL: https://github.com/llvm/llvm-project/commit/e48892ee42304284099a9b25c10d34fdc55a99f7
DIFF: https://github.com/llvm/llvm-project/commit/e48892ee42304284099a9b25c10d34fdc55a99f7.diff
LOG: [Transforms] LICM.cpp - pull out repeated getUserCost call
Pulled out of D79483
Added:
Modified:
llvm/lib/Transforms/Scalar/LICM.cpp
Removed:
################################################################################
diff --git a/llvm/lib/Transforms/Scalar/LICM.cpp b/llvm/lib/Transforms/Scalar/LICM.cpp
index e7b0eb0838b08..8e114b998354a 100644
--- a/llvm/lib/Transforms/Scalar/LICM.cpp
+++ b/llvm/lib/Transforms/Scalar/LICM.cpp
@@ -1316,10 +1316,11 @@ static bool isTriviallyReplaceablePHI(const PHINode &PN, const Instruction &I) {
/// Return true if the instruction is free in the loop.
static bool isFreeInLoop(const Instruction &I, const Loop *CurLoop,
const TargetTransformInfo *TTI) {
+ InstructionCost CostI =
+ TTI->getUserCost(&I, TargetTransformInfo::TCK_SizeAndLatency);
- if (const GetElementPtrInst *GEP = dyn_cast<GetElementPtrInst>(&I)) {
- if (TTI->getUserCost(GEP, TargetTransformInfo::TCK_SizeAndLatency) !=
- TargetTransformInfo::TCC_Free)
+ if (auto *GEP = dyn_cast<GetElementPtrInst>(&I)) {
+ if (CostI != TargetTransformInfo::TCC_Free)
return false;
// For a GEP, we cannot simply use getUserCost because currently it
// optimistically assumes that a GEP will fold into addressing mode
@@ -1333,9 +1334,9 @@ static bool isFreeInLoop(const Instruction &I, const Loop *CurLoop,
return false;
}
return true;
- } else
- return TTI->getUserCost(&I, TargetTransformInfo::TCK_SizeAndLatency) ==
- TargetTransformInfo::TCC_Free;
+ }
+
+ return CostI == TargetTransformInfo::TCC_Free;
}
/// Return true if the only users of this instruction are outside of
More information about the llvm-commits
mailing list