[PATCH] D101485: [RISCV] Teach DAG combine to fold (and (select_cc lhs, rhs, cc, -1, c), x) -> (select_cc lhs, rhs, cc, x, (and, x, c))

Luís Marques via Phabricator via llvm-commits llvm-commits at lists.llvm.org
Thu Apr 29 03:40:26 PDT 2021


luismarques accepted this revision.
luismarques added a comment.
This revision is now accepted and ready to land.

LGTM.



================
Comment at: llvm/lib/Target/RISCV/RISCVISelLowering.cpp:5183-5186
+// (or  (select_cc lhs, rhs, cc, 0, c), x)
+//   -> (select_cc lhs, rhs, cc, x, (or, x, c))
+// (xor (select_cc lhs, rhs, cc, 0, c), x)
+//   -> (select_cc lhs, rhs, cc, x, (xor, x, c))
----------------
`[AllOnes=0]`?


================
Comment at: llvm/lib/Target/RISCV/RISCVISelLowering.cpp:5192-5193
+
+  if (Slct.getOpcode() != RISCVISD::SELECT_CC || !Slct.hasOneUse())
+    return SDValue();
+
----------------
Putting this here is a clean and safe way to write it, but I wonder if this should be moved to `combineSelectCCAndUseCommutative` to avoid repeated work, or if that would be confusing and error-prone for future changes?


================
Comment at: llvm/test/CodeGen/RISCV/select-binop-identity.ll:10-11
 
 ; TODO: We can reverse this for and/or/xor. Allowing us to pull the binop into
 ; the basic block we create when we expand select.
 
----------------
Don't forget to remove the TODO.


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

https://reviews.llvm.org/D101485



More information about the llvm-commits mailing list