Hi all, It's the first LLVM backend we do for our asynchronous DSP. So, I apologize if this is a trivial question! The target-independent DAG combiner performs the following transformation: sub n, c -> add n, -c For our target, negative constants are more costly to encode. What is the best place to revert to a sub instruction? Kind regards, -- Martin www.octasic.com<http://www.octasic.com> -------------- next part -------------- An HTML attachment was scrubbed... URL: <http://lists.llvm.org/pipermail/llvm-dev/attachments/20130516/ea2e8929/attachment.html>
On Thu, May 16, 2013 at 02:03:14AM +0000, Martin Filteau wrote:> Hi all, > > It's the first LLVM backend we do for our asynchronous DSP. So, I apologize if this is a trivial question! > > The target-independent DAG combiner performs the following transformation: > > sub n, c -> add n, -c >It looks to me like this transformation would happen during the legalization phase. Is sub legal on your target? If not, you can custom lower it e.g.: setOperationAction(ISD::SUB, MVT::i32, Custom); and then handle ISD::SUB in the TargetLowering::LowerOperation() function. -Tom> For our target, negative constants are more costly to encode. What is the best place to revert to a sub instruction? > > Kind regards, > > -- Martin > > www.octasic.com<http://www.octasic.com> > > >> _______________________________________________ > LLVM Developers mailing list > LLVMdev at cs.uiuc.edu http://llvm.cs.uiuc.edu > http://lists.cs.uiuc.edu/mailman/listinfo/llvmdev
A better way to handle this is to a td pattern to match "add n, -c" to a subtraction. I believe several targets do something similar to this. Evan On May 16, 2013, at 7:12 AM, Tom Stellard <tom at stellard.net> wrote:> On Thu, May 16, 2013 at 02:03:14AM +0000, Martin Filteau wrote: >> Hi all, >> >> It's the first LLVM backend we do for our asynchronous DSP. So, I apologize if this is a trivial question! >> >> The target-independent DAG combiner performs the following transformation: >> >> sub n, c -> add n, -c >> > > It looks to me like this transformation would happen during the > legalization phase. Is sub legal on your target? If not, you > can custom lower it e.g.: > > setOperationAction(ISD::SUB, MVT::i32, Custom); > > and then handle ISD::SUB in the TargetLowering::LowerOperation() > function. > > -Tom > >> For our target, negative constants are more costly to encode. What is the best place to revert to a sub instruction? >> >> Kind regards, >> >> -- Martin >> >> www.octasic.com<http://www.octasic.com> >> >> >> > >> _______________________________________________ >> LLVM Developers mailing list >> LLVMdev at cs.uiuc.edu http://llvm.cs.uiuc.edu >> http://lists.cs.uiuc.edu/mailman/listinfo/llvmdev > > _______________________________________________ > LLVM Developers mailing list > LLVMdev at cs.uiuc.edu http://llvm.cs.uiuc.edu > http://lists.cs.uiuc.edu/mailman/listinfo/llvmdev