Patch adds new GICombineRules for G_ADD:
- G_ADD(x, G_SUB(y, x)) -> y
- G_ADD(G_SUB(y, x), x) -> y
Patch additionally adds new combine tests for AArch64 target for these new rules.
Differential D87936
[GISel] Add new combines for G_ADD mkitzan on Sep 18 2020, 1:14 PM. Authored by
Details Patch adds new GICombineRules for G_ADD:
Patch additionally adds new combine tests for AArch64 target for these new rules.
Diff Detail
Event Timeline
Comment Actions Primarily canonicalization, however depending on the target there can be perf wins. By eliminating the signed constant, there's a better chance the constant can be folded into the opcode as an immediate operand rather than being loaded into a register before being used (if the target supports immediate operands, otherwise nothing lost, eh?). Assume hypothetical target only supports 2b immediate operands to arithmetic ops and registers are 8b. Here's an example where the combine is a perf win. mov r1, -1 add r0, r1 --- sub r0, 1
Comment Actions
Comment Actions I can remove the G_ADD(x, y)->G_OR(x, y) combine if that's a blocker. Let me know if there's anything else specifically blocking the approval of this patch. Comment Actions I do think the add -> or has some value, but it should be separate with the helper function
Comment Actions Good point about using mi_match, updated the diff. Can work on the add -> or combine + helper function in a future patch. Better to not block committing the simpler combines.
Comment Actions I'll remove that combine as well. If there's more discussion and it's found to be beneficial then I can open another revision for it. Comment Actions Updates:
Comment Actions I think this looks reasonable now? I basically only have one nit.
Comment Actions Thanks for the review @paquette. I'll update the diff addressing your nit when I push the patch |
APInt to allow it to work for wide integers?