[llvm] [X86][CodeGen] Support lowering for CCMP/CTEST (PR #91747)

via llvm-commits llvm-commits at lists.llvm.org
Mon May 20 08:39:22 PDT 2024


================
@@ -54605,7 +54610,132 @@ static bool onlyZeroFlagUsed(SDValue Flags) {
   return true;
 }
 
+static SDValue combineX86SubCmpToCcmpCtest(SDNode *N, SDValue Flag,
+                                           SelectionDAG &DAG,
+                                           TargetLowering::DAGCombinerInfo &DCI,
+                                           const X86Subtarget &ST) {
+  // cmp(and/or(setcc(cc0, flag0), setcc(cc1, sub (X, Y))), 0)
+  // brcond ne
+  //
+  //  ->
+  //
+  // ccmp(X, Y, cflags/~cflags, cc0/~cc0, flag0)
+  // brcond cc1
+  //
+  //
+  // sub(and/or(setcc(cc0, flag0), setcc(cc1, sub (X, Y))), 1)
+  // brcond ne
+  //
+  // ->
+  //
+  // ccmp(X, Y, cflags/~cflags, cc0/~cc0, flag0)
+  // brcond ~cc1
+
+  // cmp(and/or(setcc(cc0, flag0), setcc(cc1, cmp (X, 0))), 0)
+  // brcond ne
+  //
+  //  ->
+  //
+  // ctest(X, X, cflags/~cflags, cc0/~cc0, flag0)
+  // brcond cc1
+  //
+  //
+  // sub(and/or(setcc(cc0, flag0), setcc(cc1, cmp (X, 0))), 1)
+  // brcond ne
+  //
+  //  ->
+  //
+  // ctest(X, X, cflags/~cflags, cc0/~cc0, flag0)
+  // brcond ~cc1
----------------
goldsteinn wrote:

Can you make these comments a bit more compact? How about:
```
  // cmp(and/or(setcc(cc0, flag0), setcc(cc1, sub/cmp (X, Y))), 0)
  // brcond ne
  //  ->
  //    ccmp(X, Y, cflags/~cflags, cc0/~cc0, flag0)
  //    brcond cc1
  //
  // sub(and/or(setcc(cc0, flag0), setcc(cc1, sub/cmp (X, Y))), 1)
  // brcond ne
  //  ->
  //    ccmp(X, Y, cflags/~cflags, cc0/~cc0, flag0)
  //    brcond cc1
```

https://github.com/llvm/llvm-project/pull/91747


More information about the llvm-commits mailing list