Skip to content

Conversation

@rootjalex
Copy link
Member

As discussed with @abadams , later lowering stages expect to see int/uint reinterprets to have been normalized to casts. This PR removes the places in find_intrinsics and lower_intrinsics that introduce reinterpret, and use cast instead.

@rootjalex rootjalex requested a review from abadams August 18, 2023 00:17
@rootjalex
Copy link
Member Author

Failures appear unrelated

@rootjalex rootjalex merged commit 708d41b into main Aug 21, 2023
@rootjalex rootjalex deleted the rootjalex/rm-reinterpret branch August 21, 2023 18:45
@pranavb-ca
Copy link
Contributor

Thank you for this @rootjalex. @prasmish- Isn't this essentially what we were talking about this morning? Can you please take a look if it helps your case?

@rootjalex
Copy link
Member Author

@pranavb-ca No problem!

Btw, I have a PR that I am working on that is aiming to improve handling of reinterpret/casts that do reinterprets, for ARM and HVX codegen. If you / your team are working on something similar, it might be useful to coordinate. I've been running into a lot of headaches with HexagonOptimize for that PR.

@rootjalex
Copy link
Member Author

An example:

x_i16 + widening_mul(y_u8, (int8)3)

On ARM, it's better to rewrite this to:

x_i16 + i16(widening_mul(y_u8, (uint8)3))

and target umlal. However, on HVX, this pattern maps to vmpybusv_acc, so we shouldn't lift to the reinterpreted widening_mul (although, for this particular example, vmpyubv_acc could be used for the operation as well). The general theme is this: on non-HVX architectures, it's almost always better to rewrite widening_mul(u, i) to reinterpret(widening_mul(u, u)) if possible (i.e. the signed operand is a positive constant), but this causes all sorts of issues with HVX codegen, which is generally better at handling mixed-signed widening_mul. I almost want to fix this by having find_intrinsics accept the Target and only apply certain rules if not targeting HVX

@pranavb-ca
Copy link
Contributor

Thanks, @rootjalex.
@prasmish is working on this on our end. I have spoken to him and he'll keep you posted.

ardier pushed a commit to ardier/Halide-mutation that referenced this pull request Mar 3, 2024
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

Successfully merging this pull request may close these issues.

4 participants