[llvm] ce0a750 - [AggressiveInstCombine] Ignore debug instructions when load combining (#70200)

Mikael Holmen via llvm-commits llvm-commits at lists.llvm.org
Thu Oct 26 01:00:18 PDT 2023


Author: Mikael Holmen
Date: 2023-10-26T09:58:54+02:00
New Revision: ce0a750fe4b04630fcb242822627d790f4c2878b

URL: https://github.com/llvm/llvm-project/commit/ce0a750fe4b04630fcb242822627d790f4c2878b
DIFF: https://github.com/llvm/llvm-project/commit/ce0a750fe4b04630fcb242822627d790f4c2878b.diff

LOG: [AggressiveInstCombine] Ignore debug instructions when load combining (#70200)

We previously included debug instructions when counting instructions when
looking for loads to combine. This meant that the presence of debug
instructions could affect optimization, as shown in the updated testcase.

This fixes #69925.

Added: 
    

Modified: 
    llvm/lib/Transforms/AggressiveInstCombine/AggressiveInstCombine.cpp
    llvm/test/Transforms/AggressiveInstCombine/AArch64/combine_ignore_debug.ll

Removed: 
    


################################################################################
diff  --git a/llvm/lib/Transforms/AggressiveInstCombine/AggressiveInstCombine.cpp b/llvm/lib/Transforms/AggressiveInstCombine/AggressiveInstCombine.cpp
index a55d01645f10eb8..d09ac1c099c1a34 100644
--- a/llvm/lib/Transforms/AggressiveInstCombine/AggressiveInstCombine.cpp
+++ b/llvm/lib/Transforms/AggressiveInstCombine/AggressiveInstCombine.cpp
@@ -706,7 +706,10 @@ static bool foldLoadsRecursive(Value *V, LoadOps &LOps, const DataLayout &DL,
        make_range(Start->getIterator(), End->getIterator())) {
     if (Inst.mayWriteToMemory() && isModSet(AA.getModRefInfo(&Inst, Loc)))
       return false;
-    if (++NumScanned > MaxInstrsToScan)
+
+    // Ignore debug info so that's not counted against MaxInstrsToScan.
+    // Otherwise debug info could affect codegen.
+    if (!isa<DbgInfoIntrinsic>(Inst) && ++NumScanned > MaxInstrsToScan)
       return false;
   }
 

diff  --git a/llvm/test/Transforms/AggressiveInstCombine/AArch64/combine_ignore_debug.ll b/llvm/test/Transforms/AggressiveInstCombine/AArch64/combine_ignore_debug.ll
index 4b41060544f7a0d..68455a1f9074ecb 100644
--- a/llvm/test/Transforms/AggressiveInstCombine/AArch64/combine_ignore_debug.ll
+++ b/llvm/test/Transforms/AggressiveInstCombine/AArch64/combine_ignore_debug.ll
@@ -2,9 +2,8 @@
 ; RUN: opt -mtriple aarch64 -aggressive-instcombine-max-scan-instrs=1 -passes="aggressive-instcombine" -S < %s | FileCheck %s -check-prefix DBG
 ; RUN: opt -strip-debug -mtriple aarch64 -aggressive-instcombine-max-scan-instrs=1 -passes="aggressive-instcombine" -S < %s | FileCheck %s -check-prefix NODBG
 
-; FIXME: The DBG and NODBG cases should be the same. I.e. we should optimize the
-; DBG case too even if there is a dbg.value.
-; This is described in https://github.com/llvm/llvm-project/issues/69925
+; The DBG and NODBG cases should be the same. I.e. we should optimize the DBG
+; case too even if there is a dbg.value.
 
 target datalayout = "E"
 
@@ -16,14 +15,9 @@ target datalayout = "E"
 define void @test() {
 ; DBG-LABEL: define void @test() {
 ; DBG-NEXT:  entry:
-; DBG-NEXT:    [[L1:%.*]] = load i16, ptr @e, align 1
+; DBG-NEXT:    [[L1:%.*]] = load i32, ptr @e, align 1
 ; DBG-NEXT:    call void @llvm.dbg.value(metadata i32 undef, metadata [[META3:![0-9]+]], metadata !DIExpression()), !dbg [[DBG5:![0-9]+]]
-; DBG-NEXT:    [[L2:%.*]] = load i16, ptr getelementptr inbounds ([[S:%.*]], ptr @e, i16 0, i32 1), align 1
-; DBG-NEXT:    [[E2:%.*]] = zext i16 [[L2]] to i32
-; DBG-NEXT:    [[E1:%.*]] = zext i16 [[L1]] to i32
-; DBG-NEXT:    [[S1:%.*]] = shl nuw i32 [[E1]], 16
-; DBG-NEXT:    [[O1:%.*]] = or i32 [[S1]], [[E2]]
-; DBG-NEXT:    store i32 [[O1]], ptr @l, align 1
+; DBG-NEXT:    store i32 [[L1]], ptr @l, align 1
 ; DBG-NEXT:    ret void
 ;
 ; NODBG-LABEL: define void @test() {


        


More information about the llvm-commits mailing list