-
Notifications
You must be signed in to change notification settings - Fork 13.5k
Missing range analysis for llvm.ucmp
and llvm.scmp
intrinsics
#130179
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
Labels
Comments
I don't think the range attribute added by inlining is really the problem here. Even if you drop it, it still doesn't fold. We're just missing some range analysis for the cmp intrinsics. (It's supported by computeConstantRange, but that's insufficient here.) |
llvm.ucmp
and llvm.scmp
intrinsics
llvm-sync bot
pushed a commit
to arm/arm-toolchain
that referenced
this issue
Apr 17, 2025
Add support for specifying range attributes in Intrinsics.td. Use this to specify the ucmp/scmp range [-1,2). This case is trickier than existing intrinsic attributes, because we need to create the attribute with the correct bitwidth. As such, the attribute construction now needs to be aware of the function type. We also need to be careful to no longer assign attributes on intrinsics with invalid signatures, as we'd make invalid assumptions about the number of arguments etc otherwise. Fixes llvm/llvm-project#130179.
var-const
pushed a commit
to ldionne/llvm-project
that referenced
this issue
Apr 17, 2025
Add support for specifying range attributes in Intrinsics.td. Use this to specify the ucmp/scmp range [-1,2). This case is trickier than existing intrinsic attributes, because we need to create the attribute with the correct bitwidth. As such, the attribute construction now needs to be aware of the function type. We also need to be careful to no longer assign attributes on intrinsics with invalid signatures, as we'd make invalid assumptions about the number of arguments etc otherwise. Fixes llvm#130179.
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Found investigating rust-lang/rust#133984
Given this IR:
Today https://llvm.godbolt.org/z/Wj8cPnK3n it optimizes to
Note, in particular, the inlined intrinsic call at the beginning:
That's an overly-broad range for
scmp
, which is always in [-1, 2).As a result, follow-up passes don't optimize away that dead
i8 2
arm of theswitch
-- I guess they trust that range and don't look at what they knowscmp
actually returns.So it would be good if either:
scmp
, asalso fixes the problem (https://llvm.godbolt.org/z/h7a55WKxK).
The text was updated successfully, but these errors were encountered: