[llvm] [InstCombine] Use the select condition to try to constant fold binops into select (PR #84696)

Matt Arsenault via llvm-commits llvm-commits at lists.llvm.org
Wed Sep 18 01:58:15 PDT 2024


================
@@ -2002,14 +2002,61 @@ Instruction *InstCombinerImpl::foldBinopWithPhiOperands(BinaryOperator &BO) {
   return NewPhi;
 }
 
-Instruction *InstCombinerImpl::foldBinOpIntoSelectOrPhi(BinaryOperator &I) {
+// Return std::nullopt if we should not fold. Return true if we should fold
+// multi-use select and false for single-use select.
+static std::optional<bool> shouldFoldOpIntoSelect(BinaryOperator &I, Value *Op,
+                                                  Value *OpOther,
+                                                  bool AllowMultiUse) {
+  if (!AllowMultiUse && !Op->hasOneUse())
+    return std::nullopt;
+  if (isa<SelectInst>(Op)) {
----------------
arsenm wrote:

Can merge this into the if above 

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


More information about the llvm-commits mailing list