[llvm] [INSTR COMBINE] implement combine select into cast (PR #114612)

via llvm-commits llvm-commits at lists.llvm.org
Fri Nov 1 15:30:02 PDT 2024


github-actions[bot] wrote:

<!--LLVM CODE FORMAT COMMENT: {clang-format}-->


:warning: C/C++ code formatter, clang-format found issues in your code. :warning:

<details>
<summary>
You can test this locally with the following command:
</summary>

``````````bash
git-clang-format --diff e549ec529c0c39cfa2fdf4ab919de406a0ef89cb ac1b070955a8de141043847b0813bf8a9e3918cd --extensions cpp -- llvm/lib/Transforms/InstCombine/InstCombineSelect.cpp
``````````

</details>

<details>
<summary>
View the diff from clang-format here.
</summary>

``````````diff
diff --git a/llvm/lib/Transforms/InstCombine/InstCombineSelect.cpp b/llvm/lib/Transforms/InstCombine/InstCombineSelect.cpp
index 2758de88c8..4e86f30100 100644
--- a/llvm/lib/Transforms/InstCombine/InstCombineSelect.cpp
+++ b/llvm/lib/Transforms/InstCombine/InstCombineSelect.cpp
@@ -3654,30 +3654,31 @@ static bool hasAffectedValue(Value *V, SmallPtrSetImpl<Value *> &Affected,
 // %any1 = uitofp i1 %any0 to float
 // ```
 // (also works with double)
-static std::optional<Instruction*> mabyeFoldIntoCast(Value* CondVal, ConstantFP *TrueVal, ConstantFP *FalseVal, Type *SelType, llvm::StringRef out) {
+static std::optional<Instruction *>
+mabyeFoldIntoCast(Value *CondVal, ConstantFP *TrueVal, ConstantFP *FalseVal,
+                  Type *SelType, llvm::StringRef out) {
   if (TrueVal->getValueAPF().convertToDouble() != 1.0) {
-    return std::optional<Instruction*>();
+    return std::optional<Instruction *>();
   }
 
   if (FalseVal->getValueAPF().convertToDouble() != 0.0) {
-    return std::optional<Instruction*>();
+    return std::optional<Instruction *>();
   }
 
   return CastInst::Create(llvm::Instruction::UIToFP, CondVal, SelType, out);
 }
 
-
 Instruction *InstCombinerImpl::visitSelectInst(SelectInst &SI) {
   Value *CondVal = SI.getCondition();
   Value *TrueVal = SI.getTrueValue();
   Value *FalseVal = SI.getFalseValue();
   Type *SelType = SI.getType();
 
-  
   if (ConstantFP *True = dyn_cast<ConstantFP>(TrueVal)) {
     if (ConstantFP *False = dyn_cast<ConstantFP>(FalseVal)) {
       if (SelType->isFloatTy() || SelType->isDoubleTy()) {
-        std::optional<Instruction*> folded = mabyeFoldIntoCast(CondVal, True, False, SelType, SI.getName());
+        std::optional<Instruction *> folded =
+            mabyeFoldIntoCast(CondVal, True, False, SelType, SI.getName());
 
         if (folded.has_value()) {
           return folded.value();

``````````

</details>


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


More information about the llvm-commits mailing list