Skip to content

Commit 2b646b5

Browse files
authored
[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.
1 parent 477c0b6 commit 2b646b5

File tree

2 files changed

+1
-23
lines changed

2 files changed

+1
-23
lines changed

llvm/lib/Transforms/Scalar/CorrelatedValuePropagation.cpp

Lines changed: 0 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -55,7 +55,6 @@ static cl::opt<bool> CanonicalizeICmpPredicatesToUnsigned(
5555
STATISTIC(NumPhis, "Number of phis propagated");
5656
STATISTIC(NumPhiCommon, "Number of phis deleted via common incoming value");
5757
STATISTIC(NumSelects, "Number of selects propagated");
58-
STATISTIC(NumMemAccess, "Number of memory access targets propagated");
5958
STATISTIC(NumCmps, "Number of comparisons propagated");
6059
STATISTIC(NumReturns, "Number of return values propagated");
6160
STATISTIC(NumDeadCases, "Number of switch cases removed");
@@ -264,23 +263,6 @@ static bool processPHI(PHINode *P, LazyValueInfo *LVI, DominatorTree *DT,
264263
return Changed;
265264
}
266265

267-
static bool processMemAccess(Instruction *I, LazyValueInfo *LVI) {
268-
Value *Pointer = nullptr;
269-
if (LoadInst *L = dyn_cast<LoadInst>(I))
270-
Pointer = L->getPointerOperand();
271-
else
272-
Pointer = cast<StoreInst>(I)->getPointerOperand();
273-
274-
if (isa<Constant>(Pointer)) return false;
275-
276-
Constant *C = LVI->getConstant(Pointer, I);
277-
if (!C) return false;
278-
279-
++NumMemAccess;
280-
I->replaceUsesOfWith(Pointer, C);
281-
return true;
282-
}
283-
284266
static bool processICmp(ICmpInst *Cmp, LazyValueInfo *LVI) {
285267
if (!CanonicalizeICmpPredicatesToUnsigned)
286268
return false;
@@ -1159,10 +1141,6 @@ static bool runImpl(Function &F, LazyValueInfo *LVI, DominatorTree *DT,
11591141
case Instruction::FCmp:
11601142
BBChanged |= processCmp(cast<CmpInst>(&II), LVI);
11611143
break;
1162-
case Instruction::Load:
1163-
case Instruction::Store:
1164-
BBChanged |= processMemAccess(&II, LVI);
1165-
break;
11661144
case Instruction::Call:
11671145
case Instruction::Invoke:
11681146
BBChanged |= processCallSite(cast<CallBase>(II), LVI);

llvm/test/Transforms/CorrelatedValuePropagation/basic.ll

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -63,7 +63,7 @@ define i8 @test3(ptr %a) nounwind {
6363
; CHECK: bb:
6464
; CHECK-NEXT: ret i8 0
6565
; CHECK: bb2:
66-
; CHECK-NEXT: [[SHOULD_BE_CONST:%.*]] = load i8, ptr @gv, align 1
66+
; CHECK-NEXT: [[SHOULD_BE_CONST:%.*]] = load i8, ptr [[A]], align 1
6767
; CHECK-NEXT: ret i8 [[SHOULD_BE_CONST]]
6868
;
6969
entry:

0 commit comments

Comments
 (0)