[llvm] 45944e7 - [RISCV] Refactor translateSetCCForBranch to prepare for D130508. NFC.
Craig Topper via llvm-commits
llvm-commits at lists.llvm.org
Mon Jul 25 15:55:01 PDT 2022
Author: Craig Topper
Date: 2022-07-25T15:54:54-07:00
New Revision: 45944e7cf45915eb2a0a2fae24e3396fc91dfc22
URL: https://github.com/llvm/llvm-project/commit/45944e7cf45915eb2a0a2fae24e3396fc91dfc22
DIFF: https://github.com/llvm/llvm-project/commit/45944e7cf45915eb2a0a2fae24e3396fc91dfc22.diff
LOG: [RISCV] Refactor translateSetCCForBranch to prepare for D130508. NFC.
D130508 handles more constants than just 1 or -1. We need to extract
the constant instead of relying isOneConstant or isAllOnesConstant.
Added:
Modified:
llvm/lib/Target/RISCV/RISCVISelLowering.cpp
Removed:
################################################################################
diff --git a/llvm/lib/Target/RISCV/RISCVISelLowering.cpp b/llvm/lib/Target/RISCV/RISCVISelLowering.cpp
index 146605782e9a3..baa19e81e4365 100644
--- a/llvm/lib/Target/RISCV/RISCVISelLowering.cpp
+++ b/llvm/lib/Target/RISCV/RISCVISelLowering.cpp
@@ -1406,18 +1406,28 @@ static void translateSetCCForBranch(const SDLoc &DL, SDValue &LHS, SDValue &RHS,
}
}
- // Convert X > -1 to X >= 0.
- if (CC == ISD::SETGT && isAllOnesConstant(RHS)) {
- RHS = DAG.getConstant(0, DL, RHS.getValueType());
- CC = ISD::SETGE;
- return;
- }
- // Convert X < 1 to 0 >= X.
- if (CC == ISD::SETLT && isOneConstant(RHS)) {
- RHS = LHS;
- LHS = DAG.getConstant(0, DL, RHS.getValueType());
- CC = ISD::SETGE;
- return;
+ if (auto *RHSC = dyn_cast<ConstantSDNode>(RHS)) {
+ int64_t C = RHSC->getSExtValue();
+ switch (CC) {
+ default: break;
+ case ISD::SETGT:
+ // Convert X > -1 to X >= 0.
+ if (C == -1) {
+ RHS = DAG.getConstant(0, DL, RHS.getValueType());
+ CC = ISD::SETGE;
+ return;
+ }
+ break;
+ case ISD::SETLT:
+ // Convert X < 1 to 0 <= X.
+ if (C == 1) {
+ RHS = LHS;
+ LHS = DAG.getConstant(0, DL, RHS.getValueType());
+ CC = ISD::SETGE;
+ return;
+ }
+ break;
+ }
}
switch (CC) {
More information about the llvm-commits
mailing list