[llvm] [X86] Add checkSignTestSetCCCombine - if X86ISD::CMP/OR is testing for signbits, attempt to test for the signbit source instead. (PR #97433)
via llvm-commits
llvm-commits at lists.llvm.org
Wed Jul 3 00:08:58 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())
----------------
goldsteinn wrote:
My guess is this is worth it even if the SRA is multi-use unless function is compiled with `-Os`. In the `or` case below think there is no downside so mult-use (not even code size).
https://github.com/llvm/llvm-project/pull/97433
More information about the llvm-commits
mailing list