Skip to content

Miscompile with opt -passes="constraint-elimination" #76713

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

Closed
mikaelholmen opened this issue Jan 2, 2024 · 5 comments
Closed

Miscompile with opt -passes="constraint-elimination" #76713

mikaelholmen opened this issue Jan 2, 2024 · 5 comments

Comments

@mikaelholmen
Copy link
Collaborator

llvm commit: 5842dfe
Reproduce with: opt -passes="constraint-elimination" bbi-90501.ll -S -o -
bbi-90501.ll.gz

There are two nested loops in the input that should finish and then we should end up at

bb.2:                                             ; preds = %bb.1
  ret i16 0

but with constraint-elimination the condition in bb.5 is changed to

  %i10 = or i1 true, %i9
  br i1 %i10, label %bb.7, label %bb.6

so we will go to

bb.7:                                             ; preds = %bb.5
  ret i16 1

instead.

@mikaelholmen
Copy link
Collaborator Author

This starts happening with e6a1657

[ConstraintElim] Add A < B if A is an increasing phi for A != B.

@fhahn : any idea what's up?

@fhahn
Copy link
Contributor

fhahn commented Jan 2, 2024

Looks like an issue with sub decomposition with negative constants, preparing a fix.

@mikaelholmen
Copy link
Collaborator Author

Thanks for the quick fix! I've verified it solves the problem I saw.

@fhahn
Copy link
Contributor

fhahn commented Jan 3, 2024

@mikaelholmen thanks for the reproducer!

@fhahn
Copy link
Contributor

fhahn commented Jan 3, 2024

(appreciated as always, thanks for your extensive testing)

fhahn added a commit to fhahn/llvm-project that referenced this issue Jan 3, 2024
fhahn added a commit to fhahn/llvm-project that referenced this issue Jan 3, 2024
The current patterns for NUWSub decompositions do not handle negative
constants correctly at the moment (causing llvm#76713).

Replace the incorrect pattern by more general code that recursively
decomposes the operands and then combines the results. This is already
done in most other places that handle operators like add/mul.

This means we fall back to the general constant handling code (fixes the
mis-compile) while also being able to support reasoning about
decomposable expressions in the SUB operands.

Fixes llvm#76713.

(cherry-picked from 3c127e8)
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

4 participants