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

big query indicated a nop, but none was found #333

Open
regehr opened this issue Jun 20, 2018 · 3 comments
Open

big query indicated a nop, but none was found #333

regehr opened this issue Jun 20, 2018 · 3 comments

Comments

@regehr
Copy link
Collaborator

regehr commented Jun 20, 2018

When Souper look for nops, it batches up the possibilities and issues a single solver query looking for the existence of a nop. If none of them work (the expected case by far) then we're done. If a nop is detected, with an unsat result, we don't know which nop is the one that worked, so we have to go and look at each one individually. If none is found, then there must be a bug in the way we aggregated the nops into a single query. That seems to be the case here. This is the smallest LHS that I can find that triggers this bug.

/home/regehr/souper-regehr/build/souper-check -solver-timeout=15 -z3-path=/usr/bin/z3 -infer-rhs -souper-infer-nop
*** oops ***
%0:i32 = var
%1:i1 = eq 0:i32, %0
%2:i32 = sub 32:i32, %0
%3:i32 = lshr 71:i32, %2
%4:i32 = select %1, 0:i32, %3
infer %4

LLVM ERROR: big query indicated a nop, but none was found 
@rsas
Copy link
Collaborator

rsas commented Jun 28, 2018

Here is the failing optimization that must be LGTM:

%0:i32 = var
%1:i1 = eq 0:i32, %0
%2:i32 = sub 32:i32, %0
%3:i32 = lshr 71:i32, %2
%4:i32 = select %1, 0:i32, %3
infer %4
result %3

@rsas
Copy link
Collaborator

rsas commented Jul 5, 2018

Alive says this optimization is wrong:

----------------------------------------
Optimization: 1
Precondition: true
  %1 = icmp eq 0, %0
  %2 = sub i32 32, %0
  %3 = lshr 71, %2
  %4 = select i1 %1, 0, %3
=>
  %4 = %3


ERROR: Target is more poisonous than Source for i32 %4

Example:
%0 i32 = 0x00000000 (0)
%1 i1 = 0x1 (1, -1)
%2 i32 = 0x00000020 (32)
%3 i32 = poison
Source value: 0x00000000 (0)
Target value: poison 

The "big nop" query is not correct in this case.

@mateon1
Copy link

mateon1 commented Aug 6, 2019

This issue bit me when using sclang to compile a program.

Original oops:

*** oops ***
%0:i64 = var
%1:i64 = var
%2:i64 = and 3:i64, %1
%3:i1 = eq %0, %2
pc %3 1:i1
%4:i64 = var
%5:i1 = ult %4, 2:i64
%6:i64 = shl %1, %4
%7:i64 = and 3:i64, %6
%8:i64 = select %5, %7, 0:i64
infer %8

LLVM ERROR: big query indicated a nop, but none was found

Reduced:

*** oops ***
%0:i64 = var
%1:i1 = ult %0, 2:i64
%2:i64 = var
%3:i64 = shl %2, %0
%4:i64 = and 3:i64, %3
%5:i64 = select %1, %4, 0:i64
infer %5

LLVM ERROR: big query indicated a nop, but none was found

I think this example is clearer.

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

No branches or pull requests

3 participants