[llvm] [InstCombine] optimize powi(X,Y)/X with Ofast (PR #67236)
via llvm-commits
llvm-commits at lists.llvm.org
Sat Sep 23 05:29:41 PDT 2023
https://github.com/vfdff created https://github.com/llvm/llvm-project/pull/67236
Fixes https://github.com/llvm/llvm-project/pull/67214
>From 96799e402d8d57ffe345bf0600c2e9e15ba54e43 Mon Sep 17 00:00:00 2001
From: zhongyunde 00443407 <zhongyunde at huawei.com>
Date: Sat, 23 Sep 2023 06:40:12 -0400
Subject: [PATCH] [InstCombine] optimize powi(X,Y)/X with Ofast
Fixes https://github.com/llvm/llvm-project/pull/67214
---
.../Transforms/InstCombine/InstCombineMulDivRem.cpp | 10 ++++++++++
llvm/test/Transforms/InstCombine/powi.ll | 10 ++++++++++
2 files changed, 20 insertions(+)
diff --git a/llvm/lib/Transforms/InstCombine/InstCombineMulDivRem.cpp b/llvm/lib/Transforms/InstCombine/InstCombineMulDivRem.cpp
index dc091ec7c60e8dd..9c13a63e394a1d5 100644
--- a/llvm/lib/Transforms/InstCombine/InstCombineMulDivRem.cpp
+++ b/llvm/lib/Transforms/InstCombine/InstCombineMulDivRem.cpp
@@ -1764,6 +1764,16 @@ Instruction *InstCombinerImpl::visitFDiv(BinaryOperator &I) {
return replaceInstUsesWith(I, Pow);
}
+ if (I.hasAllowReassoc() && I.hasNoInfs() &&
+ match(Op0, m_OneUse(m_Intrinsic<Intrinsic::powi>(m_Specific(Op1),
+ m_Value(Y))))) {
+ Constant *NegOne = ConstantInt::getAllOnesValue(Y->getType());
+ Value *Y1 = Builder.CreateAdd(Y, NegOne);
+ Type *Types[] = {Op1->getType(), Y1->getType()};
+ Value *Pow = Builder.CreateIntrinsic(Intrinsic::powi, Types, {Op1, Y1}, &I);
+ return replaceInstUsesWith(I, Pow);
+ }
+
return nullptr;
}
diff --git a/llvm/test/Transforms/InstCombine/powi.ll b/llvm/test/Transforms/InstCombine/powi.ll
index 20fe25c50a3ffc0..d58d66660690769 100644
--- a/llvm/test/Transforms/InstCombine/powi.ll
+++ b/llvm/test/Transforms/InstCombine/powi.ll
@@ -258,3 +258,13 @@ define double @different_types_powi(double %x, i32 %y, i64 %z) {
%mul = fmul reassoc double %p2, %p1
ret double %mul
}
+
+define nofpclass(nan inf) double @fdiv_powi(double %x) {
+; CHECK-LABEL: @fdiv_powi(
+; CHECK-NEXT: [[DIV:%.*]] = fmul fast double [[X:%.*]], [[X]]
+; CHECK-NEXT: ret double [[DIV]]
+;
+ %p1 = call fast double @llvm.powi.f64.i32(double %x, i32 3)
+ %div = fdiv fast double %p1, %x
+ ret double %div
+}
More information about the llvm-commits
mailing list