Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Predicates should handle poison #39

Open
davemenendez opened this issue May 27, 2017 · 2 comments
Open

Predicates should handle poison #39

davemenendez opened this issue May 27, 2017 · 2 comments
Labels

Comments

@davemenendez
Copy link
Contributor

Alive newsema accepts this optimization:

Pre: isPowerOf2(%a)
  %a = shl i4 1, %x
  %b = select 1, %x, %a
  %c = icmp ult %b, 4
=>
  %c = true

See also http://rise4fun.com/Alive/U4o

LLVM's isKnownToBeAPowerOfTwo analysis is always true for %a, no matter what is known about %x. In other words, the precondition should not constrain %x at all. This is allowed by LLVM because the analysis is not required to be accurate when its input is poison, which it will be in any case where the optimization is not a refinement.

@nunoplopes
Copy link
Owner

Thanks Dave! I agree this is a bug; this predicate should ensure power-of-2 OR poison. Right now it's missing the "OR poison" part.
This is a long discussion to have re. what are the semantics of LLVM's analyses. Most LLVM analyses have similar semantics to this power-of-2, but not all. (and it keeps changing)

@nunoplopes nunoplopes added the bug label May 29, 2017
@davemenendez
Copy link
Contributor Author

Fortunately, it seems pretty hard to trigger this bug. You need a situation where (1) the optimization is invalid when a particular source value is poison, and (2) the precondition involves an analysis of that value. My example essentially uses isPowerOf2 to indirectly bound the size of %x, but then doesn't actually use the value that's been analyzed.

It would be interesting to know whether a less-contrived example is possible.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

2 participants