Skip to content

Commit cb7cb83

Browse files
committed
[InstCombine] Add check to avoid dependent optimization order, NFC
Since PR86428, foldPowiReassoc is called by both FMul and FDiv, as the optimization of FDiv is placed after the FMul, so now it is correct we don't add the checking of FDiv for powi(X, Y) / X. But, we may add more matching scenarios later, so add the checking opcode explicitly is easier to understand.
1 parent 811ffc0 commit cb7cb83

File tree

1 file changed

+5
-2
lines changed

1 file changed

+5
-2
lines changed

llvm/lib/Transforms/InstCombine/InstCombineMulDivRem.cpp

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -582,6 +582,9 @@ Instruction *InstCombinerImpl::foldPowiReassoc(BinaryOperator &I) {
582582
};
583583

584584
Value *X, *Y, *Z;
585+
unsigned Opcode = I.getOpcode();
586+
assert((Opcode == Instruction::FMul || Opcode == Instruction::FDiv) &&
587+
"Unexpected opcode");
585588

586589
// powi(X, Y) * X --> powi(X, Y+1)
587590
// X * powi(X, Y) --> powi(X, Y+1)
@@ -596,7 +599,7 @@ Instruction *InstCombinerImpl::foldPowiReassoc(BinaryOperator &I) {
596599
// powi(x, y) * powi(x, z) -> powi(x, y + z)
597600
Value *Op0 = I.getOperand(0);
598601
Value *Op1 = I.getOperand(1);
599-
if (I.isOnlyUserOfAnyOperand() &&
602+
if (Opcode == Instruction::FMul && I.isOnlyUserOfAnyOperand() &&
600603
match(Op0, m_AllowReassoc(
601604
m_Intrinsic<Intrinsic::powi>(m_Value(X), m_Value(Y)))) &&
602605
match(Op1, m_AllowReassoc(m_Intrinsic<Intrinsic::powi>(m_Specific(X),
@@ -608,7 +611,7 @@ Instruction *InstCombinerImpl::foldPowiReassoc(BinaryOperator &I) {
608611
// This is legal when (Y - 1) can't wraparound, in which case reassoc and nnan
609612
// are required.
610613
// TODO: Multi-use may be also better off creating Powi(x,y-1)
611-
if (I.hasAllowReassoc() && I.hasNoNaNs() &&
614+
if (Opcode == Instruction::FDiv && I.hasAllowReassoc() && I.hasNoNaNs() &&
612615
match(Op0, m_OneUse(m_AllowReassoc(m_Intrinsic<Intrinsic::powi>(
613616
m_Specific(Op1), m_Value(Y))))) &&
614617
willNotOverflowSignedSub(Y, ConstantInt::get(Y->getType(), 1), I)) {

0 commit comments

Comments
 (0)