[llvm] [X86] Add checkSignTestSetCCCombine - if X86ISD::CMP/OR is testing for signbits, attempt to test for the signbit source instead. (PR #97433)

Simon Pilgrim via llvm-commits llvm-commits at lists.llvm.org
Wed Jul 3 03:15:16 PDT 2024


================
@@ -46433,6 +46433,57 @@ static SDValue combineSetCCAtomicArith(SDValue Cmp, X86::CondCode &CC,
   return LockOp;
 }
 
+// Check whether we're just testing the signbit, and whether we can simplify
+// this by tracking where the signbit came from.
+static SDValue checkSignTestSetCCCombine(SDValue Cmp, X86::CondCode &CC,
+                                         SelectionDAG &DAG) {
+  if (CC != X86::COND_S && CC != X86::COND_NS)
+    return SDValue();
+
+  SDValue Src;
+  if (Cmp.getOpcode() == X86ISD::CMP) {
+    // CMP(X,0) -> signbit test
+    if (!isNullConstant(Cmp.getOperand(1)) || !Cmp->hasOneUse())
+      return SDValue();
+    Src = Cmp.getOperand(0);
+    // Peek through a SRA node as we just need the signbit.
+    // TODO: Use SimplifyDemandedBits instead of just SRA?
+    if (Src.getOpcode() != ISD::SRA || !Src->hasOneUse())
----------------
RKSimon wrote:

The SRA one use is to avoid some regressions in sdiv fix tests that reuse the sign_extend_inreg expansion for other things - I've added a TODO for now.

I'll move the Cmp->hasOneUse check.

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


More information about the llvm-commits mailing list