The SETcc/SETULT sets carry flag in the same way as usub, so it can
be considered as a carry flag and pulled into addcarry, subcarry nodes.
Details
- Reviewers
craig.topper RKSimon spatel lebedev.ri
Diff Detail
- Repository
- rG LLVM Github Monorepo
Event Timeline
llvm/lib/CodeGen/SelectionDAG/DAGCombiner.cpp | ||
---|---|---|
2772 | Do we need any getBooleanContents checks here? |
What do you think about this idea in general? Can we assume or check if SETULT actually affects CL flag on given target?
llvm/lib/CodeGen/SelectionDAG/DAGCombiner.cpp | ||
---|---|---|
2772 | I'm not sure. But I can pass it though the getBooleanContents check below. |
llvm/lib/CodeGen/SelectionDAG/DAGCombiner.cpp | ||
---|---|---|
2773 | Use return SDValue() to match the rest of the code. |
I have not found anything about it in code comments.
I'm now investigating what is SETCCCARRY node kind about...
BTW - how come we still have the ISD::ADDE/SUBE nodes? I thought we were intending to get rid of them as the glue nodes made them difficult to work with.
What I try to do in the end is to fix https://github.com/llvm/llvm-project/issues/53432. Maybe this particular change is not good direction, but on the other hand it also helps with the test add_U320_without_i128_add already in repo.
I'm totally inexperienced with X86ISelLowering but I'm guessing I'd need to duplicate some/all DAGCombine match patters which take carry flag into account. These tend to be quite complex.
llvm/test/CodeGen/X86/addcarry.ll | ||
---|---|---|
1335 | This case looks like an easy X86 backend peephole. X86ISD::ADC with an unused flag result, 0 for RHS, LHS is a single use ADD. If so fold the ADD operands into a new X86ISD::ADC. I'm not sure about the @add_U320_without_i128_add case without staring at it for a lot longer. |
llvm/test/CodeGen/X86/addcarry.ll | ||
---|---|---|
1335 | combineSBB already does something similar, we're just missing this from combineADC |
This was intermediate change to solve https://github.com/llvm/llvm-project/issues/53432. There I want to merge sub + cmp into single sbb. Any suggestions how to solve it differently?
llvm/test/CodeGen/X86/addcarry.ll | ||
---|---|---|
1335 |
@chfast reverse-ping - any luck with working out how best to deal with add_U320_without_i128_add?
No. I tried to untangle the graph here for long time but without any meaningful results. But I believe the test can be reduced. This is not my priority any more but I may contribute a reduced tests some day.
On the high level note, using builtin_subc() or builtin_sub_with_overflow() is good enough workaround.
I also think it would be very nice to have generic addc/subc intrinsic on LLVM IR level. Then many of these carry matching could be done in LLVM IR.
Please can you rebase to see where we currently are? Also D127115 affects these tests - so maybe see whether this SETULT change is still needed after that patch or whether something else can further improve the codegen?
For what it is worth, when the dag is processed in fully topological order, and you add in D57317 , then you get optimal codegen for these tests.
Yes, this is great. Thanks for reaching out. I will try to be little involved in both then.
I'm not actively working on this one so I will probably focus on regression tests for combining cmp into sbb (as the result of recent changes to InstCombine).
This review may be stuck/dead, consider abandoning if no longer relevant.
Removing myself as reviewer in attempt to clean dashboard.
Do we need any getBooleanContents checks here?