[llvm] 2b646b5 - [CVP] Don't try to fold load/store operands to constant (#73338)
via llvm-commits
llvm-commits at lists.llvm.org
Mon Nov 27 00:17:08 PST 2023
Author: Nikita Popov
Date: 2023-11-27T09:17:03+01:00
New Revision: 2b646b598942b87f25fda1713a3c5e211585ca88
URL: https://github.com/llvm/llvm-project/commit/2b646b598942b87f25fda1713a3c5e211585ca88
DIFF: https://github.com/llvm/llvm-project/commit/2b646b598942b87f25fda1713a3c5e211585ca88.diff
LOG: [CVP] Don't try to fold load/store operands to constant (#73338)
CVP currently tries to fold load/store pointer operands to constants
using LVI. If there is a dominating condition of the form `icmp eq ptr
%p, @g`, then `%p` will be replaced with `@g`.
LVI is geared towards range-based optimizations, and is *very*
inefficient at handling simple pointer equality conditions. We have
other passes that can handle this optimization in a more efficient way,
such as IPSCCP and GVN.
Removing this optimization gives a geomean 0.4-1.2% compile-time
improvement depending on configuration. At the same time, there
is no impact on codegen.
Added:
Modified:
llvm/lib/Transforms/Scalar/CorrelatedValuePropagation.cpp
llvm/test/Transforms/CorrelatedValuePropagation/basic.ll
Removed:
################################################################################
diff --git a/llvm/lib/Transforms/Scalar/CorrelatedValuePropagation.cpp b/llvm/lib/Transforms/Scalar/CorrelatedValuePropagation.cpp
index 3229ec4f4d0f52e..1bdc441d18ea65e 100644
--- a/llvm/lib/Transforms/Scalar/CorrelatedValuePropagation.cpp
+++ b/llvm/lib/Transforms/Scalar/CorrelatedValuePropagation.cpp
@@ -55,7 +55,6 @@ static cl::opt<bool> CanonicalizeICmpPredicatesToUnsigned(
STATISTIC(NumPhis, "Number of phis propagated");
STATISTIC(NumPhiCommon, "Number of phis deleted via common incoming value");
STATISTIC(NumSelects, "Number of selects propagated");
-STATISTIC(NumMemAccess, "Number of memory access targets propagated");
STATISTIC(NumCmps, "Number of comparisons propagated");
STATISTIC(NumReturns, "Number of return values propagated");
STATISTIC(NumDeadCases, "Number of switch cases removed");
@@ -264,23 +263,6 @@ static bool processPHI(PHINode *P, LazyValueInfo *LVI, DominatorTree *DT,
return Changed;
}
-static bool processMemAccess(Instruction *I, LazyValueInfo *LVI) {
- Value *Pointer = nullptr;
- if (LoadInst *L = dyn_cast<LoadInst>(I))
- Pointer = L->getPointerOperand();
- else
- Pointer = cast<StoreInst>(I)->getPointerOperand();
-
- if (isa<Constant>(Pointer)) return false;
-
- Constant *C = LVI->getConstant(Pointer, I);
- if (!C) return false;
-
- ++NumMemAccess;
- I->replaceUsesOfWith(Pointer, C);
- return true;
-}
-
static bool processICmp(ICmpInst *Cmp, LazyValueInfo *LVI) {
if (!CanonicalizeICmpPredicatesToUnsigned)
return false;
@@ -1159,10 +1141,6 @@ static bool runImpl(Function &F, LazyValueInfo *LVI, DominatorTree *DT,
case Instruction::FCmp:
BBChanged |= processCmp(cast<CmpInst>(&II), LVI);
break;
- case Instruction::Load:
- case Instruction::Store:
- BBChanged |= processMemAccess(&II, LVI);
- break;
case Instruction::Call:
case Instruction::Invoke:
BBChanged |= processCallSite(cast<CallBase>(II), LVI);
diff --git a/llvm/test/Transforms/CorrelatedValuePropagation/basic.ll b/llvm/test/Transforms/CorrelatedValuePropagation/basic.ll
index 0ef48ea8020ec30..9fcf7c320f62dd5 100644
--- a/llvm/test/Transforms/CorrelatedValuePropagation/basic.ll
+++ b/llvm/test/Transforms/CorrelatedValuePropagation/basic.ll
@@ -63,7 +63,7 @@ define i8 @test3(ptr %a) nounwind {
; CHECK: bb:
; CHECK-NEXT: ret i8 0
; CHECK: bb2:
-; CHECK-NEXT: [[SHOULD_BE_CONST:%.*]] = load i8, ptr @gv, align 1
+; CHECK-NEXT: [[SHOULD_BE_CONST:%.*]] = load i8, ptr [[A]], align 1
; CHECK-NEXT: ret i8 [[SHOULD_BE_CONST]]
;
entry:
More information about the llvm-commits
mailing list