EVT SetCCOpVT = N1.getOperand(0).getValueType();
if (!N0C->isZero() && SetCCOpVT.isInteger() && isIntEqualitySetCC(CCVal)) {
EVT VT = N->getValueType(0);
- const APInt &ImmVal = N0C->getAPIntValue();
- CCVal = ISD::getSetCCInverse(CCVal, SetCCOpVT);
- SDValue NewN0 =
- DAG.getSetCC(SDLoc(N), VT, N1.getOperand(0), N1.getOperand(1), CCVal);
- SDValue NewN1 = DAG.getConstant(ImmVal - 1, SDLoc(N), VT);
- return DAG.getNode(ISD::ADD, SDLoc(N), VT, NewN0, NewN1);
+ APInt ImmValMinus1 = N0C->getAPIntValue() - 1;
+ // If this doesn't form ADDI, the transform won't save any instructions
+ // and may increase the number of constants we need.
+ if (ImmValMinus1.isSignedIntN(12)) {
+ CCVal = ISD::getSetCCInverse(CCVal, SetCCOpVT);
+ SDValue NewN0 =
+ DAG.getSetCC(SDLoc(N), VT, N1.getOperand(0), N1.getOperand(1), CCVal);
+ SDValue NewN1 = DAG.getConstant(ImmValMinus1, SDLoc(N), VT);
+ return DAG.getNode(ISD::ADD, SDLoc(N), VT, NewN0, NewN1);
+ }
}
}
; RV32-LABEL: select_eq_10000_10001:
; RV32: # %bb.0:
; RV32-NEXT: xor a0, a0, a1
-; RV32-NEXT: snez a0, a0
+; RV32-NEXT: seqz a0, a0
; RV32-NEXT: lui a1, 2
-; RV32-NEXT: addi a1, a1, 1809
-; RV32-NEXT: add a0, a0, a1
+; RV32-NEXT: addi a1, a1, 1810
+; RV32-NEXT: sub a0, a1, a0
; RV32-NEXT: ret
;
; RV64-LABEL: select_eq_10000_10001:
; RV64: # %bb.0:
; RV64-NEXT: xor a0, a0, a1
-; RV64-NEXT: snez a0, a0
+; RV64-NEXT: seqz a0, a0
; RV64-NEXT: lui a1, 2
-; RV64-NEXT: addiw a1, a1, 1809
-; RV64-NEXT: add a0, a0, a1
+; RV64-NEXT: addiw a1, a1, 1810
+; RV64-NEXT: sub a0, a1, a0
; RV64-NEXT: ret
%1 = icmp eq i32 %a, %b
%2 = select i1 %1, i32 10001, i32 10002
; RV32-LABEL: select_ne_10001_10002:
; RV32: # %bb.0:
; RV32-NEXT: xor a0, a0, a1
-; RV32-NEXT: seqz a0, a0
+; RV32-NEXT: snez a0, a0
; RV32-NEXT: lui a1, 2
-; RV32-NEXT: addi a1, a1, 1809
-; RV32-NEXT: add a0, a0, a1
+; RV32-NEXT: addi a1, a1, 1810
+; RV32-NEXT: sub a0, a1, a0
; RV32-NEXT: ret
;
; RV64-LABEL: select_ne_10001_10002:
; RV64: # %bb.0:
; RV64-NEXT: xor a0, a0, a1
-; RV64-NEXT: seqz a0, a0
+; RV64-NEXT: snez a0, a0
; RV64-NEXT: lui a1, 2
-; RV64-NEXT: addiw a1, a1, 1809
-; RV64-NEXT: add a0, a0, a1
+; RV64-NEXT: addiw a1, a1, 1810
+; RV64-NEXT: sub a0, a1, a0
; RV64-NEXT: ret
%1 = icmp ne i32 %a, %b
%2 = select i1 %1, i32 10001, i32 10002