[llvm-dev] Evaluate SCEV on "typically expected value"

Alexandre Isoard via llvm-dev llvm-dev at lists.llvm.org
Wed Mar 28 12:04:06 PDT 2018


Hello,

We have some transformations based on SCEV and they usually end-up making
heuristic decision based on SCEV comparison. While there are some
situations where the comparison is trivial (subtract then look at the sign
of the range), there are also a lot of situation where it is not (the range
contains 0 strictly [aka. not on the boundary]). And we then take a
"default" choice.

To improve the quality of our heuristic, I wanted to evaluate those SCEV on
"typically expected" values that the programmer would provide, sparsely, on
different scalars of a function.

I am not sure if the __builtin_expect was meant for this purpose. It is
nicely SSA friendly (it returns a value on which we can "attach" the
expectation) but maybe something akin to __builtin_assume is preferable?

Basically:

%b = i64 call @llvm.expect(i64 %a, i64 16)
%c = i64 call something(%b)
%d = i64 call something(%a)

Can be easily transformed into:

%b = i64 call @llvm.expect(i64 %a, i64 16)
%c = i64 call something_that_handle_16_great(%b)
%d = i64 call something(%a)

But it is harder to transform the second one too. The "expect" does not
propagate up.

Could we have an ExpectationTracker that does something similar?
Should it be based on @llvm.expect or a different built-in?

Ideally we could provide an "expected" range for SCEV. Where the SCEV is
not guaranteed to be, but is a good hint.

-- 
*Alexandre Isoard*
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.llvm.org/pipermail/llvm-dev/attachments/20180328/18235895/attachment.html>


More information about the llvm-dev mailing list