[CodeGenPrepare] Eliminate llvm.expect before removing empty blocks
authorJann Horn <jannh@google.com>
Thu, 4 Mar 2021 13:39:21 +0000 (14:39 +0100)
committerBenjamin Kramer <benny.kra@googlemail.com>
Thu, 4 Mar 2021 13:48:26 +0000 (14:48 +0100)
commit91c9dee3fb6d89ab3315fac1c1419614d6874b99
treee7516242e17bc3bb7a6ebdaac4b184a8512f50d8
parentbf3ac994c4d526b74044a977176e8e07d83f2049
[CodeGenPrepare] Eliminate llvm.expect before removing empty blocks

CodeGenPrepare currently first removes empty blocks, then in a loop
performs other optimizations. One of those optimizations is the removal
of call instructions that invoke @llvm.assume, which can create new
empty blocks.

This means that when a branch only contains a call to __builtin_assume(),
the empty branch will survive into MIR, and will then only be
half-removed by MIR-level optimizations (e.g. removing the branch but
leaving the condition intact).

Fix it by eliminating @llvm.expect builtin calls before removing empty
blocks.

Reviewed By: bkramer

Differential Revision: https://reviews.llvm.org/D97848
llvm/lib/CodeGen/CodeGenPrepare.cpp
llvm/test/Transforms/CodeGenPrepare/X86/delete-assume-dead-code.ll
llvm/test/Transforms/CodeGenPrepare/remove-assume-block.ll [new file with mode: 0644]