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

Incorrect fold of 'x & (-1 >> y) s>= x' #39208

Closed
nunoplopes opened this issue Dec 2, 2018 · 6 comments
Closed

Incorrect fold of 'x & (-1 >> y) s>= x' #39208

nunoplopes opened this issue Dec 2, 2018 · 6 comments
Assignees
Labels
bugzilla Issues migrated from bugzilla miscompilation

Comments

@nunoplopes
Copy link
Member

Bugzilla Link 39861
Resolution FIXED
Resolved on Jun 08, 2019 22:07
Version trunk
OS All
CC @hfinkel,@LebedevRI,@RKSimon,@regehr,@rotateright
Fixed by commit(s) 348181, 348461, 348462

Extended Description

This is a bug in test/Transforms/InstCombine/canonicalize-constant-low-bit-mask-and-icmp-sge-to-icmp-sle.ll

Output of Alive2:
declare i1 @​pv(i8 %x, i8 %y) {
%tmp0 = lshr i8 255, %y
%tmp1 = and i8 %tmp0, %x
%ret = icmp sge i8 %tmp1, %x
ret i1 %ret
}
=>
declare i1 @​pv(i8 %x, i8 %y) {
%tmp0 = lshr i8 255, %y
%1 = icmp sge i8 %tmp0, %x
ret i1 %1
}
Transformation doesn't verify!
ERROR: Value mismatch

Example:
i8 %x = 0x7e (126)
i8 %y = 0x0 (0)

Source:
i8 %tmp0 = 0xff (255, -1)
i8 %tmp1 = 0x7e (126)
i1 %ret = 0x1 (1, -1)

Target:
i8 %tmp0 = 0xff (255, -1)
i1 %1 = 0x0 (0)
Source value: 0x1 (1, -1)
Target value: 0x0 (0)

@nunoplopes
Copy link
Member Author

assigned to @LebedevRI

@LebedevRI
Copy link
Member

Hm, lookiug..

@LebedevRI
Copy link
Member

Hm, lookiug..

Okay, so that is because in
%tmp0 = lshr i8 255, %y
%y is 0. Ouch. That was not caught in the initial check, which was
rL337109 https://rise4fun.com/Alive/I3O because
Pre: isPowerOf2(C1+1)
where C1 was -1, so C1+1 would be 0, which is not PowerOf2 so it wasn't checked

Can you tell if any other canonicalize-constant-low-bit-mask-and-icmp-* are bad?

@nunoplopes
Copy link
Member Author

The only other test 'canonicalize-*' test I see failing is this:

canonicalize-constant-low-bit-mask-and-icmp-slt-to-icmp-sgt.ll

declare i1 @​pv(i8 %x, i8 %y) {
%tmp0 = lshr i8 255, %y
%tmp1 = and i8 %tmp0, %x
%ret = icmp slt i8 %tmp1, %x
ret i1 %ret
}
=>
declare i1 @​pv(i8 %x, i8 %y) {
%tmp0 = lshr i8 255, %y
%1 = icmp slt i8 %tmp0, %x
ret i1 %1
}
Transformation doesn't verify!
ERROR: Value mismatch

Example:
i8 %x = 0x7e (126)
i8 %y = 0x0 (0)

Source:
i8 %tmp0 = 0xff (255, -1)
i8 %tmp1 = 0x7e (126)
i1 %ret = 0x0 (0)

Target:
i8 %tmp0 = 0xff (255, -1)
i1 %1 = 0x1 (1, -1)
Source value: 0x0 (0)
Target value: 0x1 (1, -1)

@LebedevRI
Copy link
Member

Got alive2 to work, can confirm that this test file is failing.

The only other test 'canonicalize-*' test I see failing is this:

canonicalize-constant-low-bit-mask-and-icmp-slt-to-icmp-sgt.ll

Ok, thank you, i will take care of that.

@LebedevRI
Copy link
Member

Thanks for reporting!

@llvmbot llvmbot transferred this issue from llvm/llvm-bugzilla-archive Dec 10, 2021
This issue was closed.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bugzilla Issues migrated from bugzilla miscompilation
Projects
None yet
Development

No branches or pull requests

2 participants