diff options
author | Nikita Popov <npopov@redhat.com> | 2023-11-27 09:17:03 +0100 |
---|---|---|
committer | GitHub <noreply@github.com> | 2023-11-27 09:17:03 +0100 |
commit | 2b646b598942b87f25fda1713a3c5e211585ca88 (patch) | |
tree | 68ae6936654c5890108c0256fb7af0c57239624e | |
parent | 477c0b67a3ab30e74f3563b3f0b9d4d53caba465 (diff) | |
download | llvm-2b646b598942b87f25fda1713a3c5e211585ca88.zip llvm-2b646b598942b87f25fda1713a3c5e211585ca88.tar.gz llvm-2b646b598942b87f25fda1713a3c5e211585ca88.tar.bz2 |
[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.
-rw-r--r-- | llvm/lib/Transforms/Scalar/CorrelatedValuePropagation.cpp | 22 | ||||
-rw-r--r-- | llvm/test/Transforms/CorrelatedValuePropagation/basic.ll | 2 |
2 files changed, 1 insertions, 23 deletions
diff --git a/llvm/lib/Transforms/Scalar/CorrelatedValuePropagation.cpp b/llvm/lib/Transforms/Scalar/CorrelatedValuePropagation.cpp index 3229ec4..1bdc441 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 0ef48ea..9fcf7c3 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: |