[llvm-dev] [RFC] jump threading on std::pair<int, bool>

Friedman, Eli via llvm-dev llvm-dev at lists.llvm.org
Thu Mar 8 10:57:52 PST 2018


On 3/8/2018 6:29 AM, Hiroshi 7 Inoue via llvm-dev wrote:
>
> Hi,
>
> While comparing the code by LLVM and GCC for some major libraries, I 
> found that LLVM fails to apply jump threading with a method whose 
> return type is std::pair<int, bool> (actually, any pair of 32-bit 
> values like std::pair<bool, int> and std::pair<int, int>).
> For example, jump threading does not work for the if statement in func.
>
> std::pair<int, bool> callee(int v) {
> int a = dummy(v);
> if (a) return std::make_pair(dummy(v), true);
> else return std::make_pair(v, v < 0);
> }
>
> int func(int v) {
> std::pair<int, bool> rc = callee(v);
> if (rc.second) {
> // do something
> }
> ...
>
> SROA executed before the method inlining replaces std::pair by i64 
> without splitting in both `callee` and `func` since at this point no 
> access to the individual fields is seen to SROA.
> After inlining, jump threading fails to identify that the incoming 
> value is a constant due to additional instructions (like or, and, trunc).
>
> I would appreciate it if I could have any suggestions on how we can 
> optimization such cases.
> I am planning to enhance InstCombine pass to eliminate these 
> additional instructions before jump threading rather than enhancing 
> SROA or jump threading.
>
InstCombiner::SliceUpIllegalIntegerPHI already sort of does what you 
want... but it's currently disabled for legal integer types. Not sure 
what the performance implications would be if we run that more aggressively.

-Eli

-- 
Employee of Qualcomm Innovation Center, Inc.
Qualcomm Innovation Center, Inc. is a member of Code Aurora Forum, a Linux Foundation Collaborative Project

-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.llvm.org/pipermail/llvm-dev/attachments/20180308/3ed74064/attachment.html>


More information about the llvm-dev mailing list