[PATCH] D77922: [InstCombine] Fix debug variance issue in tryToMoveFreeBeforeNullTest

Vedant Kumar via Phabricator via llvm-commits llvm-commits at lists.llvm.org
Fri Apr 10 17:15:10 PDT 2020


vsk created this revision.
vsk added reviewers: fhahn, qcolombet.
Herald added subscribers: llvm-commits, hiraditya, aprantl.
Herald added a project: LLVM.
vsk added a subscriber: davide.

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

Depends on D77915 <https://reviews.llvm.org/D77915>.


Repository:
  rG LLVM Github Monorepo

https://reviews.llvm.org/D77922

Files:
  llvm/lib/Transforms/InstCombine/InstructionCombining.cpp
  llvm/test/Transforms/InstCombine/malloc-free-delete-dbginvar.ll


Index: llvm/test/Transforms/InstCombine/malloc-free-delete-dbginvar.ll
===================================================================
--- /dev/null
+++ 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
+}
Index: llvm/lib/Transforms/InstCombine/InstructionCombining.cpp
===================================================================
--- llvm/lib/Transforms/InstCombine/InstructionCombining.cpp
+++ llvm/lib/Transforms/InstCombine/InstructionCombining.cpp
@@ -2709,7 +2709,7 @@
   // 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);


-------------- next part --------------
A non-text attachment was scrubbed...
Name: D77922.256705.patch
Type: text/x-patch
Size: 1659 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/llvm-commits/attachments/20200411/60192c68/attachment.bin>


More information about the llvm-commits mailing list