[PATCH] D45343: Always remove null check before free
Dávid Bolvanský via Phabricator via llvm-commits
llvm-commits at lists.llvm.org
Fri Apr 6 06:00:38 PDT 2018
xbolva00 updated this revision to Diff 141324.
xbolva00 added a comment.
Added test
https://reviews.llvm.org/D45343
Files:
lib/Transforms/InstCombine/InstructionCombining.cpp
mypatch.patch
test/Transforms/InstCombine/null-check-free.ll
Index: test/Transforms/InstCombine/null-check-free.ll
===================================================================
--- /dev/null
+++ test/Transforms/InstCombine/null-check-free.ll
@@ -0,0 +1,20 @@
+; RUN: opt < %s -instcombine -S | FileCheck %s
+
+declare i8* @malloc(i32) #1
+
+declare i32 @free(...) #1
+
+; CHECK-LABEL: define i8* @nullcheckfree()(
+; CHECK: entry:
+; CHECK-NEXT: %p = alloca i8*, align 4
+; CHECK-NEXT: %call = call i8* @malloc(i32 10)
+; CHECK-NEXT: %tobool = icmp ne i8* %call, null
+; CHECK-NEXT: br i1 %tobool, label %if.then, label %if.end
+; CHECK: if.end:
+; CHECK-NEXT: %0 = load i8*, i8** %p, align 4
+; CHECK-NEXT: %call1 = call i32 bitcast (i32 (...)* @free to i32 (i8*)*)(i8* %0)
+; CHECK-NEXT: br label %if.end
+; CHECK: if.end:
+; CHECK-NEXT: %1 = load i8*, i8** %p, align 4
+; CHECK-NEXT: ret i8* %1
+}
\ No newline at end of file
Index: lib/Transforms/InstCombine/InstructionCombining.cpp
===================================================================
--- lib/Transforms/InstCombine/InstructionCombining.cpp
+++ lib/Transforms/InstCombine/InstructionCombining.cpp
@@ -2333,9 +2333,8 @@
// 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.141324.patch
Type: text/x-patch
Size: 1428 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/llvm-commits/attachments/20180406/315ccdcf/attachment.bin>
More information about the llvm-commits
mailing list