[llvm-dev] Which way to lower selects on architectures without conditional moves&

Joan Lluch via llvm-dev llvm-dev at lists.llvm.org
Sat Oct 12 00:27:09 PDT 2019


Hi Sergey,

You may also want to look at the MSP430 backend implementation. It also uses Custom Inserters to translate selects into branches. Since it is a simpler backend (meaning less lines of code) it is easier to follow.

You mentioned that you want to optimise some cases of selects. This is normally done for you by the DAGCombine code. However, if your architecture has relatively cheap branches, such ‘optimisations’ might not be always desirable. The trunk MSP430 and the AVR targets are affected by this problem, and I worked on a backend that suffers from that too. For those targets, deciding which selects should not be combined into non-branching sequences is difficult, but there are a few cases that are pretty obvious. If your target gets affected by this, you may be interested in supporting this: http://llvm.1065342.n5.nabble.com/llvm-dev-AVR-MSP430-Code-gen-improvements-for-8-bit-and-16-bit-targets-tc131716.html <http://llvm.1065342.n5.nabble.com/llvm-dev-AVR-MSP430-Code-gen-improvements-for-8-bit-and-16-bit-targets-tc131716.html>

John


> On 12 Oct 2019, at 01:34, Craig Topper via llvm-dev <llvm-dev at lists.llvm.org <mailto:llvm-dev at lists.llvm.org>> wrote:
> 
> SelectionDAG can't have control flow. For X86 we match selects on old CPUs or on types that don't support cmov to pseudo cmov instructions during isel. Those cmov instructions are marked as "UsesCustomInserter" in the InstrInfo td files. X86TargetLowering::EmitInstrWithCustomInserter will then expand those pseudo instructions into control flow by creating new MachineBasicBlocks and branches. Most of that code is in X86TargetLowering::EmitLoweredSelect.
> 
> 
> ~Craig
> 
> 
> On Fri, Oct 11, 2019 at 4:20 PM s.ignatov via llvm-dev <llvm-dev at lists.llvm.org <mailto:llvm-dev at lists.llvm.org>> wrote:
> Hello,
> 
> We have the architecture without conditional moves. Which way can we 
> lower select?
> 
> As we know there was the special pass a long time ago, but it was deleted.
> 
> commit c3591a0d48ce045bbf5ae0d78a41f3dae4bb99db
> Author: Chris Lattner <sabre at nondot.org <mailto:sabre at nondot.org>>
> Date:   Tue Feb 19 07:49:17 2008 +0000
> 
>      remove the LowerSelect pass.  The last client was the old Sparc 
> backend, which is long dead by now.
> 
>      llvm-svn: 47323
> 
> The problem is that if we use this pass we lose some useful special 
> optimizing cases for selects, e.g. replacing it by min/max.
> 
> Does anyone have some experience with such architecture?
> 
> We're trying to generate some "if-then-else" on SelectionDAG now.
> 
> Could anyone show the way to generate "if-then-else" constructs on 
> SelectionDAG?
> 
> Thanks in advance,
> 
> Sergey.
> 
> _______________________________________________
> LLVM Developers mailing list
> llvm-dev at lists.llvm.org <mailto:llvm-dev at lists.llvm.org>
> https://lists.llvm.org/cgi-bin/mailman/listinfo/llvm-dev <https://lists.llvm.org/cgi-bin/mailman/listinfo/llvm-dev>
> _______________________________________________
> LLVM Developers mailing list
> llvm-dev at lists.llvm.org <mailto:llvm-dev at lists.llvm.org>
> https://lists.llvm.org/cgi-bin/mailman/listinfo/llvm-dev

-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.llvm.org/pipermail/llvm-dev/attachments/20191012/ed502997/attachment.html>


More information about the llvm-dev mailing list