[PATCH] D72319: [InstCombine] Adding Z / (1.0 / Y) => (Y * Z)
Raghesh Aloor via Phabricator via llvm-commits
llvm-commits at lists.llvm.org
Thu Jan 9 06:56:19 PST 2020
raghesh updated this revision to Diff 237069.
raghesh edited the summary of this revision.
raghesh removed a reviewer: llvm-commits.
raghesh added a comment.
This revision is updated with the expected change in the testcase test/Transforms/InstCombine/fdiv-to-fmul-opt.ll. Other comments are addressed too.
CHANGES SINCE LAST ACTION
https://reviews.llvm.org/D72319/new/
https://reviews.llvm.org/D72319
Files:
llvm/lib/Transforms/InstCombine/InstCombineMulDivRem.cpp
llvm/test/Transforms/InstCombine/fdiv.ll
Index: llvm/test/Transforms/InstCombine/fdiv.ll
===================================================================
--- llvm/test/Transforms/InstCombine/fdiv.ll
+++ llvm/test/Transforms/InstCombine/fdiv.ll
@@ -187,12 +187,12 @@
ret float %div2
}
-; Z / (1.0 / Y)
+; Z / (1.0 / Y) ==> Y * Z
define float @div_with_div_denominator_with_one_as_numerator_extra_use(float %x, float %y, float %z) {
; CHECK-LABEL: @div_with_div_denominator_with_one_as_numerator_extra_use(
; CHECK-NEXT: [[DIV1:%.*]] = fdiv float 1.000000e+00, [[Y:%.*]]
-; CHECK-NEXT: [[DIV2:%.*]] = fdiv reassoc arcp float [[Z:%.*]], [[DIV1]]
+; CHECK-NEXT: [[DIV2:%.*]] = fmul reassoc arcp float [[Y]], [[Z:%.*]]
; CHECK-NEXT: call void @use_f32(float [[DIV1]])
; CHECK-NEXT: ret float [[DIV2]]
;
Index: llvm/lib/Transforms/InstCombine/InstCombineMulDivRem.cpp
===================================================================
--- llvm/lib/Transforms/InstCombine/InstCombineMulDivRem.cpp
+++ llvm/lib/Transforms/InstCombine/InstCombineMulDivRem.cpp
@@ -1239,6 +1239,14 @@
Value *YZ = Builder.CreateFMulFMF(Y, Op0, &I);
return BinaryOperator::CreateFDivFMF(YZ, X, &I);
}
+ // Z / (1.0 / Y) => (Y * Z)
+ //
+ // This is a special case of Z / (X / Y) => (Y * Z) / X, with X = 1.0. The
+ // m_OneUse check is avoided because even in the case of the multiple uses
+ // for 1.0/Y, the number of instructions remain the same and a division is
+ // replaced by a multiplication.
+ if (match(Op1, m_FDiv(m_SpecificFP(1.0), m_Value(Y))))
+ return BinaryOperator::CreateFMulFMF(Y, Op0, &I);
}
if (I.hasAllowReassoc() && Op0->hasOneUse() && Op1->hasOneUse()) {
-------------- next part --------------
A non-text attachment was scrubbed...
Name: D72319.237069.patch
Type: text/x-patch
Size: 1696 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/llvm-commits/attachments/20200109/344094a8/attachment.bin>
More information about the llvm-commits
mailing list