1
0
mirror of https://github.com/RPCS3/llvm-mirror.git synced 2024-10-23 04:52:54 +02:00
llvm-mirror/test/Transforms/Reassociate
Chad Rosier 2e3937b806 [Reassociate] Add negated value of negative constant to the Duplicates list.
In OptimizeAdd, we scan the operand list to see if there are any common factors
between operands that can be factored out to reduce the number of multiplies
(e.g., 'A*A+A*B*C+D' -> 'A*(A+B*C)+D'). For each operand of the operand list, we
only consider unique factors (which is tracked by the Duplicate set). Now if we
find a factor that is a negative constant, we add the negated value as a factor
as well, because we can percolate the negate out. However, we mistakenly don't
add this negated constant to the Duplicates set.

Consider the expression A*2*-2 + B. Obviously, nothing to factor.

For the added value A*2*-2 we over count 2 as a factor without this change,
which causes the assert reported in PR30256.  The problem is that this code is
assuming that all the multiply operands of the add are already reassociated.
This change avoids the issue by making OptimizeAdd tolerate multiplies which
haven't been completely optimized; this sort of works, but we're doing wasted
work: we'll end up revisiting the add later anyway.

Another possible approach would be to enforce RPO iteration order more strongly.
If we have RedoInsts, we process them immediately in RPO order, rather than
waiting until we've finished processing the whole function. Intuitively, it
seems like the natural approach: reassociation works on expression trees, so
the optimization only works in one direction. That said, I'm not sure how
practical that is given the current Reassociate; the "optimal" form for an
expression depends on its use list (see all the uses of "user_back()"), so
Reassociate is really an iterative optimization of sorts, so any changes here
would probably get messy.

PR30256

Differential Revision: https://reviews.llvm.org/D30228

llvm-svn: 296003
2017-02-23 18:49:03 +00:00
..
2002-05-15-AgressiveSubMove.ll
2002-05-15-MissedTree.ll
2002-05-15-SubReassociate.ll
2002-07-09-DominanceProblem.ll
2003-08-12-InfiniteLoop.ll
2005-09-01-ArrayOutOfBounds.ll
2006-04-27-ReassociateVector.ll
2011-01-26-UseAfterFree.ll
2012-05-08-UndefLeak.ll
2012-06-08-InfiniteLoop.ll
absorption.ll
add_across_block_crash.ll
basictest.ll
canonicalize-neg-const.ll
commute.ll
crash2.ll
crash.ll
deadcode.ll
factorize-again.ll
fast-AgressiveSubMove.ll
fast-ArrayOutOfBounds.ll
fast-basictest.ll
fast-fp-commute.ll
fast-mightymul.ll
fast-MissedTree.ll
fast-multistep.ll
fast-ReassociateVector.ll
fast-SubReassociate.ll
fp-commute.ll
fp-expr.ll
inverses.ll
looptest.ll
mightymul.ll
min_int.ll
mixed-fast-nonfast-fp.ll
mulfactor.ll
multistep.ll
negation1.ll
negation.ll
no-op.ll
optional-flags.ll
otherops.ll
pr12245.ll
pr21205.ll
pr28367.ll
propagate-flags.ll
reassoc-intermediate-fnegs.ll
reassociate-deadinst.ll
repeats.ll
secondary.ll
shift-factor.ll
shifttest.ll
subtest.ll
vaarg_movable.ll
wrap-flags.ll
xor_reassoc.ll