[PATCH] Constant fold llvm.expect(c, ...) -> c

Chandler Carruth chandlerc at google.com
Mon Jan 26 10:30:42 PST 2015


On Mon, Jan 26, 2015 at 10:29 AM, Pete Cooper <peter_cooper at apple.com>
wrote:

> On Jan 26, 2015, at 10:24 AM, Chandler Carruth <chandlerc at google.com>
> wrote:
>
>
> On Sun, Jan 25, 2015 at 9:37 PM, Pete Cooper <peter_cooper at apple.com>
> wrote:
>
>> Hi hfinkel,
>>
>> This teaches the constant folder that an llvm.expect intrinsic with a
>> constant as the first operand will return that constant.
>>
>> This reduces the size of an LTO'd llc by over 1% due to branches which
>> can be removed once the constant is propagated.
>>
>
> I really don't understand this.
>
> The design llvm.expect was specifically for LowerExpect to remove *all* of
> these intrinsics from the IR? Why isn't that working?
>
> Looks like LowerExpect is only added in populateFunctionPassManager, which
> is only called by clang, opt, and bug point.  There’s no call to this in
> llvm-lto.
>
> I still think its worthwhile to constant fold expect as soon as possible
> as this patch does, but it looks like we also need that pass in the LTO
> pipeline.
>

I really don't think it is. We should be running LowerExpect really early
in every single pass pipeline because, as you saw, there are tons of passes
we would have to teach about it otherwise. Not constant folding is, if
anything, a nice way to flush these issues out.
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.llvm.org/pipermail/llvm-commits/attachments/20150126/34b2ad13/attachment.html>


More information about the llvm-commits mailing list