[PATCH] D146512: [TLI] Fold ~X s>/u< ~Y --> Y s>/u< X

Simon Pilgrim via Phabricator via llvm-commits llvm-commits at lists.llvm.org
Tue Mar 21 04:38:54 PDT 2023


RKSimon added a comment.

Thanks for taking a look at this!



================
Comment at: llvm/lib/CodeGen/SelectionDAG/TargetLowering.cpp:4982
+  // ~X u< ~Y --> Y u< X
+  if ((Cond == ISD::SETGT || Cond == ISD::SETULE) && N0.getOpcode() == ISD::XOR &&
+      N0.getValueType().isInteger()) {
----------------
Take a look at https://github.com/llvm/llvm-project/blob/3a8f161a3401edeb58e018e2d389dd2413a6417f/llvm/lib/Transforms/InstCombine/InstCombineCompares.cpp#L6501

This shows its safe to handle all icmp predicates - and handles cases where one operand is a constant which can be constant folded


================
Comment at: llvm/lib/CodeGen/SelectionDAG/TargetLowering.cpp:4987
+        if (isAllOnesConstant(N0.getOperand(1)) ||
+            ISD::isBuildVectorAllOnes(N0.getOperand(1).getNode()))
+          return DAG.getSetCC(dl, VT, N1.getOperand(0), N0.getOperand(0), Cond);
----------------
You should be able to use llvm::isBitwiseNot to detect this


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D146512



More information about the llvm-commits mailing list