This is an archive of the discontinued LLVM Phabricator instance.

Reassociate x + -0.1234 * y into x - 0.1234 * y (part 2)
ClosedPublic

Authored by mcrosier on Sep 15 2014, 2:59 PM.

Details

Summary

This is a follow up patch to http://reviews.llvm.org/D4904.

This gives CSE/GVN more options to eliminate duplicate expressions. However, this implementation is significantly less rigid and adds support for other operations such as integer add/sub/urem/srem/sdiv/etc. I need to rerun the performance numbers, but I thought I would begin the review process in the meantime.

Please have a look,

Chad

Diff Detail

Event Timeline

mcrosier updated this revision to Diff 13733.Sep 15 2014, 2:59 PM
mcrosier retitled this revision from to Reassociate x + -0.1234 * y into x - 0.1234 * y (part 2).
mcrosier updated this object.
mcrosier edited the test plan for this revision. (Show Details)
mcrosier added a subscriber: Unknown Object (MLST).
rengolin added a subscriber: rengolin.EditedSep 24 2014, 9:02 AM

Hi Chad,

I get this failure when running on ARM:

/work/llvm/src/llvm/test/Transforms/Reassociate/canonicalize-neg-const.ll:120:15: error: expected string not found in input
; CHECK-NEXT: fmul double %y, 1.234000e-01

<stdin>:57:21: note: scanning from here
define double @test9(double %x, double %y) {

<stdin>:58:5: note: possible intended match here
%mul = fmul double 1.234000e-01, %y

Looks like the position of the arguments is not deterministic?

Renato,
Did you run the test multiple times to verify the non-determinism. It's possible I uploaded a stale patch. Regardless, I'll investigate.

Thanks,

Chad

Chad,

It *always* happens on ARM. I believe this is not "random", but depends on other unknown (to me) dynamic factors.

cheers,
--renato

It *always* happens on ARM. I believe this is not "random", but depends on other unknown (to me) dynamic factors.

Thanks, Renato. I'll take a look.

One of the purposes of the reassociation pass is to canonicalize operands based on "rank." If the behavior isn't random, I imagine I just uploaded a stale patch.

Chad

mcrosier updated this revision to Diff 15649.Oct 31 2014, 2:35 PM
mcrosier updated this object.

Update and rebase to address Renato's comments.

Hi Chad,

no issues on ARM. Thanks!

--renato

chandlerc accepted this revision.Nov 1 2014, 6:50 PM
chandlerc edited edge metadata.

Generally looks good. Some minor code improvements suggested, but nothing significant really.

lib/Transforms/Scalar/Reassociate.cpp
1948–1955

Rather than this, it would be nice to write in a way that there is only one test of the constant type:

if (auto *CI = dyn_cast<ConstantInt>(C)) {
  // ..
} else if (auto *CF = dyn_cast<ConstantFP>(C)) {
  // ..
} else {
  return nullptr;
}
1977

The shortening "Usr" is a bit ... awkward to me. ;] Is there a problem with just calling it "UserOpcode"?

This revision is now accepted and ready to land.Nov 1 2014, 6:50 PM
mcrosier closed this revision.Nov 3 2014, 11:23 AM

Thanks, Chandler. Committed r221171.

test/Transforms/Reassociate/canonicalize-neg-const.ll