This is an archive of the discontinued LLVM Phabricator instance.

[InstCombine] powi(x, y) * powi(x, z) -> powi(x, y + z)
ClosedPublic

Authored by xbolva00 on Sep 17 2021, 12:50 AM.

Details

Summary

We already have pow(x, y) * pow(x, z) -> pow(x, y + z) transformation, but we are missing same transformation for powi (power is integer).

Requires reassoc.

Diff Detail

Event Timeline

xbolva00 created this revision.Sep 17 2021, 12:50 AM
xbolva00 requested review of this revision.Sep 17 2021, 12:50 AM
Herald added a project: Restricted Project. · View Herald TranscriptSep 17 2021, 12:50 AM
xbolva00 updated this revision to Diff 373162.Sep 17 2021, 12:52 AM

One more neg. test (different bases).

Pre-commit tests please, so it's easier to see transforms vs. negative tests.
We need to propagate the FMF to the new powi (should be able to compare against the existing 'pow' tests to see if we're missing any corner cases).

I'd vary at least one positive test to have extra FMF (eg, "fast"), so we know everything is transferred as expected.

And we need at least one more test like this:

define double @different_types_powi(double %x, i32 %y, i64 %z) {
  %p1 = tail call double @llvm.powi.f64.i32(double %x, i32 %y)
  %p2 = tail call double @llvm.powi.f64.i64(double %x, i64 %z)
  %mul = fmul reassoc double %p2, %p1
  ret double %mul
}
xbolva00 updated this revision to Diff 373324.Sep 17 2021, 1:37 PM

Tests added & precommited.

Pre-commit tests please, so it's easier to see transforms vs. negative tests.
We need to propagate the FMF to the new powi (should be able to compare against the existing 'pow' tests to see if we're missing any corner cases).

I'd vary at least one positive test to have extra FMF (eg, "fast"), so we know everything is transferred as expected.

And we need at least one more test like this:

define double @different_types_powi(double %x, i32 %y, i64 %z) {
  %p1 = tail call double @llvm.powi.f64.i32(double %x, i32 %y)
  %p2 = tail call double @llvm.powi.f64.i64(double %x, i64 %z)
  %mul = fmul reassoc double %p2, %p1
  ret double %mul
}

Thanks!

different_types_powi

gotcha, added type check.

spatel accepted this revision.Sep 19 2021, 7:09 AM

LGTM

llvm/test/Transforms/InstCombine/powi.ll
82–202

I don't think this actually tests the pattern that we want. We just swapped the names of y and z, so it's functionally the same as the previous test. Just commute the fmul operands instead?

This revision is now accepted and ready to land.Sep 19 2021, 7:09 AM
This revision was automatically updated to reflect the committed changes.