[llvm-commits] [PATCH] InstCombine: remove malloc+free if malloc's only uses are comparisons to null

Matti Niemenmaa matti.niemenmaa+llvm at iki.fi
Thu May 27 07:55:16 PDT 2010


On 2010-05-22 12:52, Matti Niemenmaa wrote:
> On 2010-05-22 01:55, Chris Lattner wrote:
>> A couple more requests :)
>>
>> +++ test/Transforms/InstCombine/malloc-free-delete2.ll (revision 0)
>> @@ -0,0 +1,11 @@
>> +; RUN: opt< %s -instcombine -S | FileCheck %s
>> +define i1 @foo() {
>> +; CHECK: @foo
>> +; CHECK-NEXT: ret i1 false
>> + %m = call i8* @malloc(i64 1)
>> + %z = icmp eq i8* %m, null
>> + call void @free(i8* %m)
>> + ret i1 %z
>> +}
>> +declare i8* @malloc(i64)
>> +declare void @free(i8*)
>>
>> Please merge this into
>> test/Transforms/InstCombine/malloc-free-delete.ll since it already
>> uses filecheck, thanks!
>
> Done. I removed -globaldce from that as well, since it wasn't depending
> on it.
>
>> + if (const ICmpInst *ICI = dyn_cast<ICmpInst>(*UI)) {
>> + ICmpInst::Predicate Pred = ICI->getPredicate();
>> + if (Pred == ICmpInst::ICMP_EQ || Pred == ICmpInst::ICMP_NE&&
>>
>> Please use ICI->isEquality()
>>
>> + (isa<ConstantPointerNull>(ICI->getOperand(0)) ||
>> + isa<ConstantPointerNull>(ICI->getOperand(1))))
>>
>> comparisons against null will put the null on the RHS of the compare,
>> just check operand #1.
>
> Both done in the attached, thanks for the simplifications.

Ping?




More information about the llvm-commits mailing list