[llvm] [InstCombine] Add missing fold for `fsqrt(select(b, c1, c2)) => select(b, fsqrt(c1), fsqrt(c2))` (PR #113084)
via llvm-commits
llvm-commits at lists.llvm.org
Sun Oct 20 06:17:38 PDT 2024
llvmbot wrote:
<!--LLVM PR SUMMARY COMMENT-->
@llvm/pr-subscribers-llvm-transforms
Author: Rajveer Singh Bharadwaj (Rajveer100)
<details>
<summary>Changes</summary>
Resolves #<!-- -->110591
---
Full diff: https://github.com/llvm/llvm-project/pull/113084.diff
1 Files Affected:
- (modified) llvm/lib/Transforms/InstCombine/InstructionCombining.cpp (+8)
``````````diff
diff --git a/llvm/lib/Transforms/InstCombine/InstructionCombining.cpp b/llvm/lib/Transforms/InstCombine/InstructionCombining.cpp
index c8b9f166b16020..911e5baba8a4de 100644
--- a/llvm/lib/Transforms/InstCombine/InstructionCombining.cpp
+++ b/llvm/lib/Transforms/InstCombine/InstructionCombining.cpp
@@ -1699,6 +1699,14 @@ Instruction *InstCombinerImpl::FoldOpIntoSelect(Instruction &Op, SelectInst *SI,
if (SI->getType()->isIntOrIntVectorTy(1))
return nullptr;
+ if (auto *II = dyn_cast<IntrinsicInst>(&Op)) {
+ if (II->getIntrinsicID() == Intrinsic::sqrt) {
+ Value *NewTV = Builder.CreateUnaryIntrinsic(Intrinsic::sqrt, TV, nullptr, "sqrt_fold");
+ Value *NewFV = Builder.CreateUnaryIntrinsic(Intrinsic::sqrt, FV, nullptr, "sqrt_fold");
+ return SelectInst::Create(SI->getCondition(), NewTV, NewFV, "", nullptr, SI);
+ }
+ }
+
// Test if a FCmpInst instruction is used exclusively by a select as
// part of a minimum or maximum operation. If so, refrain from doing
// any other folding. This helps out other analyses which understand
``````````
</details>
https://github.com/llvm/llvm-project/pull/113084
More information about the llvm-commits
mailing list