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

[Instcombine] -instcombine-verify-known-bits failure. #109957

Closed
JonPsson1 opened this issue Sep 25, 2024 · 5 comments
Closed

[Instcombine] -instcombine-verify-known-bits failure. #109957

JonPsson1 opened this issue Sep 25, 2024 · 5 comments
Assignees

Comments

@JonPsson1
Copy link
Contributor

tc_instcomb_knownbits.tar.gz

opt -mtriple=systemz-unknown -mcpu=z15 -O1 tc_instcomb_knownbits.bc -instcombine-verify-known-bits -o /dev/null

Mismatched known bits for %rem.i = srem i32 %conv.i, -1 in f
computeKnownBits(): 0000000000000000000000000000000?
SimplifyDemandedBits(): ????????????????????????????????

#8 0x000002aa01d6825c llvm::InstCombinerImpl::SimplifyDemandedInstructionBits

@RKSimon @jf-botto @nikic

@RKSimon
Copy link
Collaborator

RKSimon commented Sep 25, 2024

CC @artagnon who is looking at something related on #109121

@nikic nikic self-assigned this Sep 25, 2024
@nikic nikic closed this as completed in 5ef02a3 Sep 25, 2024
@nikic
Copy link
Contributor

nikic commented Sep 25, 2024

I fixed the immediate problem in 5ef02a3.

It would make sense to also use KnownBits::srem() here, but I noticed that the implementation (

if (RHS.isConstant() && RHS.getConstant().isPowerOf2()) {
) only covers positive power of 2, while demanded bits simplification takes the absolute value ( ).

augusto2112 pushed a commit to augusto2112/llvm-project that referenced this issue Sep 26, 2024
When dividing by -1 we were breaking out of the code entirely,
while we should fall through to computeKnownBits().

This fixes an instcombine-verify-known-bits discrepancy.

Fixes llvm#109957.
@artagnon
Copy link
Contributor

It would make sense to also use KnownBits::srem() here, but I noticed that the implementation (

if (RHS.isConstant() && RHS.getConstant().isPowerOf2()) {

) only covers positive power of 2, while demanded bits simplification takes the absolute value (


).

I think the abs() doesn't make sense, since srem with a negative RHS is flipped into one with a positive RHS, changing LHS as appropriate. I tried exercising the abs() with different tests, with the same result: the change seems to be an NFC.

@nikic
Copy link
Contributor

nikic commented Sep 27, 2024

@artagnon Good point. Do you want to submit a PR to switch that code to KnownBits::srem?

@artagnon
Copy link
Contributor

@artagnon Good point. Do you want to submit a PR to switch that code to KnownBits::srem?

On it. I'm currently working through the reasoning.

xgupta pushed a commit to xgupta/llvm-project that referenced this issue Oct 4, 2024
When dividing by -1 we were breaking out of the code entirely,
while we should fall through to computeKnownBits().

This fixes an instcombine-verify-known-bits discrepancy.

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

No branches or pull requests

5 participants