[llvm] [X86] Set up the framework for optimization of CCMP/CTEST (PR #84603)
via llvm-commits
llvm-commits at lists.llvm.org
Sat May 11 09:15:32 PDT 2024
================
@@ -3377,7 +3377,9 @@ X86TargetLowering::getJumpConditionMergingParams(Instruction::BinaryOps Opc,
const Value *Lhs,
const Value *Rhs) const {
using namespace llvm::PatternMatch;
- int BaseCost = BrMergingBaseCostThresh.getValue();
+ // Disable condition merging when CCMP is available b/c we can eliminate
+ // branches in a more efficient way.
+ int BaseCost = Subtarget.hasCCMP() ? -1 : BrMergingBaseCostThresh.getValue();
----------------
goldsteinn wrote:
> @goldsteinn We can't lower `(and/or setcc, setcc)` as `ccmp` b/c CCMP has a CMP semantic. Instead, what we need to need to do is sth like
>
> 1. Combine the DAG
>
> ```
> // sub(and(setcc(cc1, ...), setcc(cc2, sub (X, Y))), 1)
> // brcond ne
> //
> // ->
> //
> // ccmp(X, Y, cc1, cc2)
> // brcond cc2
> //
> // if only flag has users.
> ```
>
> 2. Define fragment for `ccmp`
> 3. add pattern for CCMP using the fragment
>
> I drafted a patch locally and found that it's not simpler than the MIR pass.
>
Is that #91747?
If so I disagree that it is not simpler... re-patching BBs in the MachineInst phase
is definitely a large source of the complexity of this patch.
> IIUC, some checks in `canConvert` are conservative and not real restrictions. It should not have more restriction than DAGCombine + pattern match approach. The function is borrowed from AArch64ConditionalCompares.cpp,
>
> > probably best to do as soon as possible so we have more context during DAG lowering
>
> Which context you think we need? AArch64ConditionalCompares.cpp was designed to run immediately before the early if-conversion pass.
What I mean is current DAGCombiner runs on BBs, so if are going to be merging BBs, doing so earlier
will improve the rest of lowering.
Based on the two missing cases in #91747, can they not be fixed on in simplifyCFG?
https://github.com/llvm/llvm-project/pull/84603
More information about the llvm-commits
mailing list