[llvm] [X86] Set up the framework for optimization of CCMP/CTEST (PR #84603)
Shengchen Kan via llvm-commits
llvm-commits at lists.llvm.org
Wed May 8 12:47:02 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();
----------------
KanRobert 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 more complex than the MIR pass.
IIUC, some checks in `canConvert` are conservative and not real restrictions, it's borrowed from AArch64ConditionalCompares.cpp, which was designed to run
immediately before the early if-conversion pass.
https://github.com/llvm/llvm-project/pull/84603
More information about the llvm-commits
mailing list