Skip to content

Commit 8c0278c

Browse files
committed
[InstCombine] Add missing fold for fsqrt(select(b, c1, c2)) => select(b, fsqrt(c1), fsqrt(c2))
Resolves #110591
1 parent 1bbf3a3 commit 8c0278c

File tree

1 file changed

+11
-0
lines changed

1 file changed

+11
-0
lines changed

llvm/lib/Transforms/InstCombine/InstructionCombining.cpp

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1699,6 +1699,17 @@ Instruction *InstCombinerImpl::FoldOpIntoSelect(Instruction &Op, SelectInst *SI,
16991699
if (SI->getType()->isIntOrIntVectorTy(1))
17001700
return nullptr;
17011701

1702+
if (auto *II = dyn_cast<IntrinsicInst>(&Op)) {
1703+
if (II->getIntrinsicID() == Intrinsic::sqrt) {
1704+
Value *NewTV = Builder.CreateUnaryIntrinsic(Intrinsic::sqrt, TV, nullptr,
1705+
"sqrt_fold");
1706+
Value *NewFV = Builder.CreateUnaryIntrinsic(Intrinsic::sqrt, FV, nullptr,
1707+
"sqrt_fold");
1708+
return SelectInst::Create(SI->getCondition(), NewTV, NewFV, "", nullptr,
1709+
SI);
1710+
}
1711+
}
1712+
17021713
// Test if a FCmpInst instruction is used exclusively by a select as
17031714
// part of a minimum or maximum operation. If so, refrain from doing
17041715
// any other folding. This helps out other analyses which understand

0 commit comments

Comments
 (0)