[PATCH] D130508: [RISCV] Teach translateSetCCForBranch to help improve constant materialization.

Philip Reames via Phabricator via llvm-commits llvm-commits at lists.llvm.org
Mon Jul 25 14:53:29 PDT 2022


reames requested changes to this revision.
reames added inline comments.


================
Comment at: llvm/lib/Target/RISCV/RISCVISelLowering.cpp:1409
 
-  // 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();
----------------
Please land the refactor to introduce the switch and rebase.


================
Comment at: llvm/lib/Target/RISCV/RISCVISelLowering.cpp:1417
+      // Or X > C to C >= C+1 if it could use LUI.
+      if (C == -1 ||
+          (!isInt<12>(C) && isInt<12>(C + 1)) ||
----------------
Can't we generalize this to be if RISCVMatInt::getIntMatCost(C+1) < RISCVMatInt::getIntMatCost(C)?


Repository:
  rG LLVM Github Monorepo

CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D130508/new/

https://reviews.llvm.org/D130508



More information about the llvm-commits mailing list