[PATCH] D109149: [DAG] Fold select_cc setgt X, -1, C, ~C -> xor (ashr X, BW-1), C

Dave Green via Phabricator via llvm-commits llvm-commits at lists.llvm.org
Thu Sep 2 06:49:38 PDT 2021


dmgreen added inline comments.


================
Comment at: llvm/lib/CodeGen/SelectionDAG/DAGCombiner.cpp:22873
+        DAG.getConstant(CmpOpVT.getScalarSizeInBits() - 1, DL, CmpOpVT));
+    return DAG.getNode(ISD::XOR, DL, VT, DAG.getSExtOrTrunc(ASR, DL, VT),
+                       DAG.getSExtOrTrunc(CC == ISD::SETLT ? N3 : N2, DL, VT));
----------------
arsenm wrote:
> Is it really beneficial if this cast is necessary? Should this check the compared and selected types match (or maybe allow truncate, if it's free)
Any of the selecti32i64 and selecti8i32 tests will involve sign extending, and all look like they produce less or equal numbers of instructions. I've not seen any cases where it made it unprofitable (but may not have tried all possibilities).


================
Comment at: llvm/lib/CodeGen/SelectionDAG/DAGCombiner.cpp:22877
+
+  // Fold select_cc seteq (ashr X, BW-1), -1, A, B -> select_cc setlt X, 0, A, B
+  if (CC == ISD::SETEQ && N0.getOpcode() == ISD::SRA &&
----------------
foad wrote:
> Shouldn't this be done in SimplifySetCC, i.e. for all setCC regardless of whether they are used in a select_cc or not?
Oh yeah! Will do.


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

https://reviews.llvm.org/D109149



More information about the llvm-commits mailing list