[llvm] [RISCV] Reverse (add x, (zext c)) back to (select c, (add x, 1), x) (PR #87236)

Yingwei Zheng via llvm-commits llvm-commits at lists.llvm.org
Mon Apr 1 06:27:25 PDT 2024


================
@@ -52,12 +52,59 @@ class RISCVCodeGenPrepare : public FunctionPass,
   }
 
   bool visitInstruction(Instruction &I) { return false; }
+  bool visitAdd(BinaryOperator &BO);
   bool visitAnd(BinaryOperator &BO);
   bool visitIntrinsicInst(IntrinsicInst &I);
 };
 
 } // end anonymous namespace
 
+/// InstCombine will canonicalize selects of binary ops where the identity is
+/// zero to zexts:
+///
+/// select c, (add x, 1), x -> add x, (zext c)
----------------
dtcxzyw wrote:

Can we also handle `select c, (sub x, 1), x -> add x, (sext c)`? 


https://github.com/llvm/llvm-project/pull/87236


More information about the llvm-commits mailing list