[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
Thu Jun 6 09:59:47 PDT 2024


================
@@ -1951,14 +1951,60 @@ 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:

Braces 

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


More information about the llvm-commits mailing list