[PATCH] D53356: [InstCombine] Teach the move free before null test opti how to deal with noop casts

Quentin Colombet via Phabricator via llvm-commits llvm-commits at lists.llvm.org
Tue Oct 16 21:56:29 PDT 2018


qcolombet created this revision.
qcolombet added reviewers: spatel, majnemer.
Herald added a reviewer: javed.absar.
Herald added a subscriber: kristof.beyls.

InstCombine features an optimization that essentially replaces:
if (a)

  free(a)

into:
free(a)

Right now, this optimization is gated by the minsize attribute and therefore
we only perform it if we can prove that we are going to be able to eliminate
the branch and the destination block.

However when casts are involved the optimization would fail to apply, because
the optimization was not smart enough to realize that it is possible to also
move the casts away from the destination block and that is harmless to the
performance since they are just noops.
E.g.,
foo(int *a)
if (a)

  free((char*)a)

Wouldn't be optimized by instcombine, because

- We would refuse to hoist the `bitcast i32* %a to i8` in the source block
- We would fail to see that `bitcast i32* %a to i8` and %a are the same value.

This patch fixes both these problems:

- It teaches the pattern matching of the comparison how to look

through casts.

- It checks that whether the additional instruction in the destination block

can be hoisted and are harmless performance-wise.

- It hoists all the code of the destination block in the source block.


Repository:
  rL LLVM

https://reviews.llvm.org/D53356

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

-------------- next part --------------
A non-text attachment was scrubbed...
Name: D53356.169948.patch
Type: text/x-patch
Size: 5131 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/llvm-commits/attachments/20181017/e30950aa/attachment.bin>


More information about the llvm-commits mailing list