Skip to content

Commit bd9bb31

Browse files
committed
[InstCombine] add restrict reassoc for the powi(X,Y) / X
add restrict reassoc for the powi(X,Y) / X according the discuss on PR69998.
1 parent 2938f1c commit bd9bb31

File tree

2 files changed

+16
-5
lines changed

2 files changed

+16
-5
lines changed

llvm/lib/Transforms/InstCombine/InstCombineMulDivRem.cpp

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -616,8 +616,8 @@ Instruction *InstCombinerImpl::foldPowiReassoc(BinaryOperator &I) {
616616
// are required.
617617
// TODO: Multi-use may be also better off creating Powi(x,y-1)
618618
if (I.hasAllowReassoc() && I.hasNoNaNs() &&
619-
match(Op0, m_OneUse(m_Intrinsic<Intrinsic::powi>(m_Specific(Op1),
620-
m_Value(Y)))) &&
619+
match(Op0, m_OneUse(m_AllowReassoc(m_Intrinsic<Intrinsic::powi>(
620+
m_Specific(Op1), m_Value(Y))))) &&
621621
willNotOverflowSignedSub(Y, ConstantInt::get(Y->getType(), 1), I)) {
622622
Constant *NegOne = ConstantInt::getAllOnesValue(Y->getType());
623623
return createPowiExpr(I, *this, Op1, Y, NegOne);

llvm/test/Transforms/InstCombine/powi.ll

Lines changed: 14 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -313,7 +313,7 @@ define double @fdiv_pow_powi(double %x) {
313313
; CHECK-NEXT: [[DIV:%.*]] = fmul reassoc nnan double [[X:%.*]], [[X]]
314314
; CHECK-NEXT: ret double [[DIV]]
315315
;
316-
%p1 = call double @llvm.powi.f64.i32(double %x, i32 3)
316+
%p1 = call reassoc double @llvm.powi.f64.i32(double %x, i32 3)
317317
%div = fdiv reassoc nnan double %p1, %x
318318
ret double %div
319319
}
@@ -323,7 +323,7 @@ define float @fdiv_powf_powi(float %x) {
323323
; CHECK-NEXT: [[DIV:%.*]] = call reassoc nnan float @llvm.powi.f32.i32(float [[X:%.*]], i32 99)
324324
; CHECK-NEXT: ret float [[DIV]]
325325
;
326-
%p1 = call float @llvm.powi.f32.i32(float %x, i32 100)
326+
%p1 = call reassoc float @llvm.powi.f32.i32(float %x, i32 100)
327327
%div = fdiv reassoc nnan float %p1, %x
328328
ret float %div
329329
}
@@ -347,10 +347,21 @@ define double @fdiv_pow_powi_multi_use(double %x) {
347347
define float @fdiv_powf_powi_missing_reassoc(float %x) {
348348
; CHECK-LABEL: @fdiv_powf_powi_missing_reassoc(
349349
; CHECK-NEXT: [[P1:%.*]] = call float @llvm.powi.f32.i32(float [[X:%.*]], i32 100)
350-
; CHECK-NEXT: [[DIV:%.*]] = fdiv nnan float [[P1]], [[X]]
350+
; CHECK-NEXT: [[DIV:%.*]] = fdiv reassoc nnan float [[P1]], [[X]]
351351
; CHECK-NEXT: ret float [[DIV]]
352352
;
353353
%p1 = call float @llvm.powi.f32.i32(float %x, i32 100)
354+
%div = fdiv reassoc nnan float %p1, %x
355+
ret float %div
356+
}
357+
358+
define float @fdiv_powf_powi_missing_reassoc1(float %x) {
359+
; CHECK-LABEL: @fdiv_powf_powi_missing_reassoc1(
360+
; CHECK-NEXT: [[P1:%.*]] = call reassoc float @llvm.powi.f32.i32(float [[X:%.*]], i32 100)
361+
; CHECK-NEXT: [[DIV:%.*]] = fdiv nnan float [[P1]], [[X]]
362+
; CHECK-NEXT: ret float [[DIV]]
363+
;
364+
%p1 = call reassoc float @llvm.powi.f32.i32(float %x, i32 100)
354365
%div = fdiv nnan float %p1, %x
355366
ret float %div
356367
}

0 commit comments

Comments
 (0)