[llvm] 4831f4b - [InstCombine] Fix debug variance issue in tryToMoveFreeBeforeNullTest

Vedant Kumar via llvm-commits llvm-commits at lists.llvm.org
Mon Apr 13 10:55:27 PDT 2020


Author: Vedant Kumar
Date: 2020-04-13T10:55:17-07:00
New Revision: 4831f4b7bdeb22e405248c45b3ea607a6b28b991

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

LOG: [InstCombine] Fix debug variance issue in tryToMoveFreeBeforeNullTest

Fix an issue where the presence of debug info could disable an
optimization in tryToMoveFreeBeforeNullTest.

Added: 
    llvm/test/Transforms/InstCombine/malloc-free-delete-dbginvar.ll

Modified: 
    llvm/lib/Transforms/InstCombine/InstructionCombining.cpp

Removed: 
    


################################################################################
diff  --git a/llvm/lib/Transforms/InstCombine/InstructionCombining.cpp b/llvm/lib/Transforms/InstCombine/InstructionCombining.cpp
index 4f86cdd9bb8d..cd5126884dad 100644
--- a/llvm/lib/Transforms/InstCombine/InstructionCombining.cpp
+++ b/llvm/lib/Transforms/InstCombine/InstructionCombining.cpp
@@ -2709,7 +2709,7 @@ static Instruction *tryToMoveFreeBeforeNullTest(CallInst &FI,
   // If there are more than 2 instructions, check that they are noops
   // i.e., they won't hurt the performance of the generated code.
   if (FreeInstrBB->size() != 2) {
-    for (const Instruction &Inst : *FreeInstrBB) {
+    for (const Instruction &Inst : FreeInstrBB->instructionsWithoutDebug()) {
       if (&Inst == &FI || &Inst == FreeInstrBBTerminator)
         continue;
       auto *Cast = dyn_cast<CastInst>(&Inst);

diff  --git a/llvm/test/Transforms/InstCombine/malloc-free-delete-dbginvar.ll b/llvm/test/Transforms/InstCombine/malloc-free-delete-dbginvar.ll
new file mode 100644
index 000000000000..a3c4f47fd45e
--- /dev/null
+++ b/llvm/test/Transforms/InstCombine/malloc-free-delete-dbginvar.ll
@@ -0,0 +1,22 @@
+; Check that the instcombine result is the same with/without debug info.
+; This is a regression test for a function taken from malloc-free-delete.ll.
+
+; RUN: opt < %s -instcombine -S > %t.no_dbg.ll
+; RUN: opt < %s -debugify-each -instcombine -S > %t.ll
+; RUN: 
diff  %t.no_dbg.ll %t.ll
+
+declare void @free(i8*)
+
+define void @test12(i32* %foo) minsize {
+entry:
+  %tobool = icmp eq i32* %foo, null
+  br i1 %tobool, label %if.end, label %if.then
+
+if.then:                                          ; preds = %entry
+  %bitcast = bitcast i32* %foo to i8*
+  tail call void @free(i8* %bitcast)
+  br label %if.end
+
+if.end:                                           ; preds = %entry, %if.then
+  ret void
+}


        


More information about the llvm-commits mailing list