[PATCH] D45343: [InstCombine] Always remove null check before free
Dávid Bolvanský via Phabricator via llvm-commits
llvm-commits at lists.llvm.org
Wed Apr 11 21:19:29 PDT 2018
xbolva00 updated this revision to Diff 142111.
xbolva00 added a comment.
Patch updated with suggested changes by @lebedev.ri
https://reviews.llvm.org/D45343
Files:
lib/Transforms/InstCombine/InstructionCombining.cpp
test/Transforms/InstCombine/malloc-free-delete.ll
Index: test/Transforms/InstCombine/malloc-free-delete.ll
===================================================================
--- test/Transforms/InstCombine/malloc-free-delete.ll
+++ test/Transforms/InstCombine/malloc-free-delete.ll
@@ -99,7 +99,7 @@
;; Then, performing a dead elimination will remove the comparison.
;; This is what happens with -O1 and upper.
; CHECK-LABEL: @test6(
-define void @test6(i8* %foo) minsize {
+define void @test6(i8* %foo) {
; CHECK: %tobool = icmp eq i8* %foo, null
;; Call to free moved
; CHECK-NEXT: tail call void @free(i8* %foo)
Index: lib/Transforms/InstCombine/InstructionCombining.cpp
===================================================================
--- lib/Transforms/InstCombine/InstructionCombining.cpp
+++ lib/Transforms/InstCombine/InstructionCombining.cpp
@@ -2327,15 +2327,15 @@
if (isa<ConstantPointerNull>(Op))
return eraseInstFromFunction(FI);
- // If we optimize for code size, try to move the call to free before the null
- // test so that simplify cfg can remove the empty block and dead code
- // elimination the branch. I.e., helps to turn something like:
+ // Try to move the call to free before the null test so that simplify cfg can
+ // remove the empty block and dead code elimination the branch.
+ // I.e., helps to turn something like:
// if (foo) free(foo);
// into
// free(foo);
- if (MinimizeSize)
- if (Instruction *I = tryToMoveFreeBeforeNullTest(FI))
- return I;
+
+ if (Instruction *I = tryToMoveFreeBeforeNullTest(FI))
+ return I;
return nullptr;
}
-------------- next part --------------
A non-text attachment was scrubbed...
Name: D45343.142111.patch
Type: text/x-patch
Size: 1573 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/llvm-commits/attachments/20180412/8206d6a6/attachment.bin>
More information about the llvm-commits
mailing list