[llvm] [RISCV] Break the (czero_eqz x, (setne x, 0)) -> x combine into 2 combines. (PR #90428)
Yingwei Zheng via llvm-commits
llvm-commits at lists.llvm.org
Sun Apr 28 20:52:38 PDT 2024
================
@@ -16165,28 +16165,36 @@ SDValue RISCVTargetLowering::PerformDAGCombine(SDNode *N,
return performSELECTCombine(N, DAG, Subtarget);
case RISCVISD::CZERO_EQZ:
case RISCVISD::CZERO_NEZ: {
- SDValue LHS = N->getOperand(0);
- SDValue RHS = N->getOperand(1);
- // czero_eq X, (xor Y, 1) -> czero_ne X, Y if Y is 0 or 1.
- // czero_ne X, (xor Y, 1) -> czero_eq X, Y if Y is 0 or 1.
- if (RHS.getOpcode() == ISD::XOR && isOneConstant(RHS.getOperand(1))) {
- SDValue Cond = RHS.getOperand(0);
+ SDValue Val = N->getOperand(0);
+ SDValue Cond = N->getOperand(1);
+
+ unsigned Opc = N->getOpcode();
+
+ // czero_eqz x, x -> x
+ if (Opc && Val == Cond)
+ return Val;
+
+ unsigned InvOpc =
+ Opc == RISCVISD::CZERO_EQZ ? RISCVISD::CZERO_NEZ : RISCVISD::CZERO_EQZ;
+
+ // czero_eqz X, (xor Y, 1) -> czero_nez X, Y if Y is 0 or 1.
+ // czero_nez X, (xor Y, 1) -> czero_eqz X, Y if Y is 0 or 1.
+ if (Cond.getOpcode() == ISD::XOR && isOneConstant(Cond.getOperand(1))) {
+ Cond = Cond.getOperand(0);
APInt Mask = APInt::getBitsSetFrom(Cond.getValueSizeInBits(), 1);
- if (DAG.MaskedValueIsZero(Cond, Mask)) {
- unsigned NewOpc = N->getOpcode() == RISCVISD::CZERO_EQZ
- ? RISCVISD::CZERO_NEZ
- : RISCVISD::CZERO_EQZ;
- return DAG.getNode(NewOpc, SDLoc(N), N->getValueType(0), LHS, Cond);
- }
+ if (DAG.MaskedValueIsZero(Cond, Mask))
+ return DAG.getNode(InvOpc, SDLoc(N), N->getValueType(0), Val, Cond);
+ }
----------------
dtcxzyw wrote:
Cond should be reset to `N->getOperand(1)`. Please add a test for `czero_eqz X, (xor (setcc y, 0, ne), 1)`.
https://github.com/llvm/llvm-project/pull/90428
More information about the llvm-commits
mailing list