[PATCH 1/1] DAGCombiner: Add (A - (0-B)) -> A+B optimization

Jan Vesely jan.vesely at rutgers.edu
Tue Sep 23 18:05:10 PDT 2014


On Tue, 2014-09-23 at 15:21 -0400, Chad Rosier wrote:
> Testcase?

I'm not sure how to add one. The situation is tested in
test/Transforms/InstCombine/sub.ll (test4) and indeed "opt -instcombine"
work even without the patch.
Is there a way to test DAGCombiner in a similar (generic) way, or do I
need to add a backend specific test?

It's not clear to me why the instcombine and DAG combine nedd both to do
this kind of optimization.

jan

> 
> > Signed-off-by: Jan Vesely <jan.vesely at rutgers.edu>
> > ---
> >  lib/CodeGen/SelectionDAG/DAGCombiner.cpp | 4 ++++
> >  1 file changed, 4 insertions(+)
> >
> > diff --git a/lib/CodeGen/SelectionDAG/DAGCombiner.cpp
> > b/lib/CodeGen/SelectionDAG/DAGCombiner.cpp
> > index 33e7059..bc39fe3 100644
> > --- a/lib/CodeGen/SelectionDAG/DAGCombiner.cpp
> > +++ b/lib/CodeGen/SelectionDAG/DAGCombiner.cpp
> > @@ -1794,6 +1794,10 @@ SDValue DAGCombiner::visitSUB(SDNode *N) {
> >    // fold (A+B)-B -> A
> >    if (N0.getOpcode() == ISD::ADD && N0.getOperand(1) == N1)
> >      return N0.getOperand(0);
> > +  // fold (A - (0-B)) -> A+B
> > +  if (N1.getOpcode() == ISD::SUB && isa<ConstantSDNode>(N1.getOperand(0))
> > &&
> > +      cast<ConstantSDNode>(N1.getOperand(0))->isNullValue())
> > +    return DAG.getNode(ISD::ADD, SDLoc(N), VT, N0, N1.getOperand(1));
> >    // fold C2-(A+C1) -> (C2-C1)-A
> >    if (N1.getOpcode() == ISD::ADD && N0C && N1C1) {
> >      SDValue NewC = DAG.getConstant(N0C->getAPIntValue() -
> > N1C1->getAPIntValue(),
> > --
> > 1.9.3
> >
> > _______________________________________________
> > llvm-commits mailing list
> > llvm-commits at cs.uiuc.edu
> > http://lists.cs.uiuc.edu/mailman/listinfo/llvm-commits
> >
> 
> 

-- 
Jan Vesely <jan.vesely at rutgers.edu>
-------------- next part --------------
A non-text attachment was scrubbed...
Name: signature.asc
Type: application/pgp-signature
Size: 819 bytes
Desc: This is a digitally signed message part
URL: <http://lists.llvm.org/pipermail/llvm-commits/attachments/20140923/05b0a3f1/attachment.sig>


More information about the llvm-commits mailing list