forked from OSchip/llvm-project
[InstSimplify] sqrt(X) * sqrt(X) --> X
This was misplaced in InstCombine. We can loosen the FMF as a follow-up step. llvm-svn: 325965
This commit is contained in:
parent
ebc6bc8188
commit
db53d1847b
|
@ -4251,6 +4251,12 @@ static Value *SimplifyFMulInst(Value *Op0, Value *Op1, FastMathFlags FMF,
|
|||
if (FMF.noNaNs() && FMF.noSignedZeros() && match(Op1, m_AnyZero()))
|
||||
return Op1;
|
||||
|
||||
// sqrt(X) * sqrt(X) --> X
|
||||
Value *X;
|
||||
if (FMF.isFast() && Op0 == Op1 &&
|
||||
match(Op0, m_Intrinsic<Intrinsic::sqrt>(m_Value(X))))
|
||||
return X;
|
||||
|
||||
return nullptr;
|
||||
}
|
||||
|
||||
|
|
|
@ -620,10 +620,6 @@ Instruction *InstCombiner::visitFMul(BinaryOperator &I) {
|
|||
|
||||
if (Op0 == Op1) {
|
||||
if (IntrinsicInst *II = dyn_cast<IntrinsicInst>(Op0)) {
|
||||
// sqrt(X) * sqrt(X) -> X
|
||||
if (AllowReassociate && II->getIntrinsicID() == Intrinsic::sqrt)
|
||||
return replaceInstUsesWith(I, II->getOperand(0));
|
||||
|
||||
// fabs(X) * fabs(X) -> X * X
|
||||
if (II->getIntrinsicID() == Intrinsic::fabs) {
|
||||
Instruction *FMulVal = BinaryOperator::CreateFMul(II->getOperand(0),
|
||||
|
|
|
@ -172,19 +172,8 @@ define float @test11(float %x, float %y) {
|
|||
ret float %c
|
||||
}
|
||||
|
||||
; PR21126: http://llvm.org/bugs/show_bug.cgi?id=21126
|
||||
; With unsafe/fast math, sqrt(X) * sqrt(X) is just X.
|
||||
declare double @llvm.sqrt.f64(double)
|
||||
|
||||
define double @sqrt_squared1(double %f) {
|
||||
; CHECK-LABEL: @sqrt_squared1(
|
||||
; CHECK-NEXT: ret double [[F:%.*]]
|
||||
;
|
||||
%sqrt = call double @llvm.sqrt.f64(double %f)
|
||||
%mul = fmul fast double %sqrt, %sqrt
|
||||
ret double %mul
|
||||
}
|
||||
|
||||
; With unsafe/fast math, sqrt(X) * sqrt(X) is just X,
|
||||
; but make sure another use of the sqrt is intact.
|
||||
; Note that the remaining fmul is altered but is not 'fast'
|
||||
|
|
|
@ -203,3 +203,18 @@ define float @fdiv_neg_swapped2(float %f) {
|
|||
%div = fdiv nnan float %f, %neg
|
||||
ret float %div
|
||||
}
|
||||
|
||||
; PR21126: http://llvm.org/bugs/show_bug.cgi?id=21126
|
||||
; With unsafe/fast math, sqrt(X) * sqrt(X) is just X.
|
||||
|
||||
declare double @llvm.sqrt.f64(double)
|
||||
|
||||
define double @sqrt_squared(double %f) {
|
||||
; CHECK-LABEL: @sqrt_squared(
|
||||
; CHECK-NEXT: ret double [[F:%.*]]
|
||||
;
|
||||
%sqrt = call double @llvm.sqrt.f64(double %f)
|
||||
%mul = fmul fast double %sqrt, %sqrt
|
||||
ret double %mul
|
||||
}
|
||||
|
||||
|
|
Loading…
Reference in New Issue