[llvm-commits] [pr12979][patch/rfc] Clear nsw/nuw in gvn

Daniel Berlin dberlin at dberlin.org
Fri Jun 1 19:39:26 PDT 2012


On Fri, Jun 1, 2012 at 9:33 PM, Rafael Espíndola
<rafael.espindola at gmail.com> wrote:
>>> %a = load i32* %p, !range !1
>>> %b = load i32* %p, !range !2
>>>
>>> I think the resulting range should be the *intersection*, and not the
>>> union of the ranges.  Someone says: "I'm sure this value is between 0
>>> and 5", and someone else says "I'm sure that value is between 3 and
>>> 6".  Then we know that the value must be between 3 and 5;  we don't
>>> need to expand our beliefs to be between 0 and 6.
>>> (of course this reasoning assumes that ranges are always conservative,
>>> which must be the case, anyway)
>>>
>> This is right.
>
> I think it should be the union. The logic is similar to what is being
> applied to tbaa. Consider someone implementing tagged types with an
> union in C++:
>
> struct foo {
>  char tag;
>  union {
>    bool a;
>    enum zed b;
>  };
> };
>
> now consider code accessing a variable x of type foo*:
>
> if (x->tag == 42) {
>  do something with x->a;
> } else {
>  do something with x->b;
> }
>
> we have one load in each side of the branch. Each will have a range
> matching the union field. If we were to create a single load above the
> if, it could see a bool or an enum, so the range must be the union.
>
> About TBAA, in the end Nuno analysis in the second email (using the
> lowest common ancestor)  is correct, no?

Yes, roughly, assuming they are in the same tree.

>  Some interesting cases
>
> * Two loads from different languages: They cannot alias, so there is
> no ancestor and we will simply drop the tbaa.

This is not what the LLVM assembly guide says, as i quoted ;)
It says loads in two different tbaa trees are considered to alias.

I don't disagree with your point that two loads in two different
languages can't alias, but how do you know when the loads are from
"two different languages"? :)

Each llvm bitcode file is going to have a tbaa tree, whether they are
from different languages or not.

Either these trees need to be merged somehow, or something, or else
you will have no way of saying anything about loads inlined from
multiple bc file into another bc file, and that seems like a shame.




More information about the llvm-commits mailing list