Skip to content

Commit 1cab01e

Browse files
committed
[GVN] Skip debug instructions in findDominatingValue function
findDominatingValue has a search limit, and when it is reached, optimization is not applied. This patch fixes the issue that this limit also takes into account debug intrinsics, so the result of optimization can depend from the presence of debug info.
1 parent e152ed6 commit 1cab01e

File tree

2 files changed

+4
-6
lines changed

2 files changed

+4
-6
lines changed

llvm/lib/Transforms/Scalar/GVN.cpp

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1147,13 +1147,11 @@ static Value *findDominatingValue(const MemoryLocation &Loc, Type *LoadTy,
11471147
BasicBlock *FromBB = From->getParent();
11481148
BatchAAResults BatchAA(*AA);
11491149
for (BasicBlock *BB = FromBB; BB; BB = BB->getSinglePredecessor())
1150-
for (auto I = BB == FromBB ? From->getReverseIterator() : BB->rbegin(),
1151-
E = BB->rend();
1152-
I != E; ++I) {
1150+
for (auto *Inst = BB == FromBB ? From : BB->getTerminator();
1151+
Inst != nullptr; Inst = Inst->getPrevNonDebugInstruction()) {
11531152
// Stop the search if limit is reached.
11541153
if (++NumVisitedInsts > MaxNumVisitedInsts)
11551154
return nullptr;
1156-
Instruction *Inst = &*I;
11571155
if (isModSet(BatchAA.getModRefInfo(Inst, Loc)))
11581156
return nullptr;
11591157
if (auto *LI = dyn_cast<LoadInst>(Inst))

llvm/test/Transforms/GVN/load-through-select-dbg.ll

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -11,9 +11,9 @@ define i32 @foo(ptr %a, ptr %b) {
1111
; CHECK-NEXT: call void @llvm.dbg.declare(metadata ptr undef, metadata [[META4:![0-9]+]], metadata !DIExpression()), !dbg [[DBG10:![0-9]+]]
1212
; CHECK-NEXT: [[TMP1:%.*]] = load i32, ptr [[B]], align 4
1313
; CHECK-NEXT: [[COND:%.*]] = icmp slt i32 [[TMP0]], [[TMP1]]
14+
; CHECK-NEXT: [[TMP2:%.*]] = select i1 [[COND]], i32 [[TMP0]], i32 [[TMP1]]
1415
; CHECK-NEXT: [[PTR:%.*]] = select i1 [[COND]], ptr [[A]], ptr [[B]]
15-
; CHECK-NEXT: [[RES:%.*]] = load i32, ptr [[PTR]], align 4
16-
; CHECK-NEXT: ret i32 [[RES]]
16+
; CHECK-NEXT: ret i32 [[TMP2]]
1717
;
1818
entry:
1919
%0 = load i32, ptr %a, align 4

0 commit comments

Comments
 (0)