[llvm-bugs] [Bug 43559] New: Poor codegen for targets with no native shifts

via llvm-bugs llvm-bugs at lists.llvm.org
Fri Oct 4 03:17:20 PDT 2019


https://bugs.llvm.org/show_bug.cgi?id=43559

            Bug ID: 43559
           Summary: Poor codegen for targets with no native shifts
           Product: libraries
           Version: trunk
          Hardware: PC
                OS: All
            Status: NEW
          Severity: enhancement
          Priority: P
         Component: Common Code Generator Code
          Assignee: unassignedbugs at nondot.org
          Reporter: joan.lluch at icloud.com
                CC: llvm-bugs at lists.llvm.org

This is an extension of bug 43542. This is a report of the same issue for the
following functions:

DAGCombiner::SimplifySelectCC
DAGCombiner::foldSelectCCToShiftAnd
static SDValue foldExtendedSignBitTest

Creation of shifts as a replacement of selects or extensions should be avoided
in DAGCombiner if shifts are not efficiently supported by the target. 

The following IR functions are originators or the reported issue through
slightly different paths for the MSP430 target:

; Function Attrs: norecurse nounwind readnone
define dso_local i16 @test0(i16 %a) local_unnamed_addr #0 {
entry:
  %cmp = icmp slt i16 %a, 0
  %cond = select i1 %cmp, i16 -1, i16 0
  ret i16 %cond
}

; Function Attrs: norecurse nounwind readnone
define dso_local i16 @test1(i16 %a) local_unnamed_addr #0 {
entry:
  %cmp = icmp slt i16 %a, 0
  %cond = select i1 %cmp, i16 1, i16 0
  ret i16 %cond
}

; Function Attrs: norecurse nounwind readnone
define dso_local i16 @test2(i16 %a) local_unnamed_addr #0 {
entry:
  %cmp = icmp slt i16 %a, 0
  %cond = select i1 %cmp, i16 2, i16 0
  ret i16 %cond
}

; Function Attrs: norecurse nounwind readnone
define dso_local i16 @test3(i16 %a) local_unnamed_addr #0 {
entry:
  %cmp = icmp slt i16 %a, 0
  %cond = select i1 %cmp, i16 3, i16 0
  ret i16 %cond
}



The resulting code for the MSP430 is this, which is suboptimal:

        .globl  test0
        .p2align        1
        .type   test0, at function
test0:
        swpb    r12
        sxt     r12
        rra     r12
        rra     r12
        rra     r12
        rra     r12
        rra     r12
        rra     r12
        rra     r12
        ret
.Lfunc_end0:
        .size   test0, .Lfunc_end0-test0

        .globl  test1
        .p2align        1
        .type   test1, at function
test1:
        swpb    r12
        mov.b   r12, r12
        clrc
        rrc     r12
        rra     r12
        rra     r12
        rra     r12
        rra     r12
        rra     r12
        rra     r12
        ret
.Lfunc_end1:
        .size   test1, .Lfunc_end1-test1

        .globl  test2
        .p2align        1
        .type   test2, at function
test2:
        swpb    r12
        mov.b   r12, r12
        clrc
        rrc     r12
        rra     r12
        rra     r12
        rra     r12
        rra     r12
        rra     r12
        and     #2, r12
        ret
.Lfunc_end2:
        .size   test2, .Lfunc_end2-test2

        .globl  test3
        .p2align        1
        .type   test3, at function
test3:
        swpb    r12
        sxt     r12
        rra     r12
        rra     r12
        rra     r12
        rra     r12
        rra     r12
        rra     r12
        rra     r12
        and     #3, r12
        ret
.Lfunc_end3:
        .size   test3, .Lfunc_end3-test3

-- 
You are receiving this mail because:
You are on the CC list for the bug.
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.llvm.org/pipermail/llvm-bugs/attachments/20191004/ae9adbf2/attachment.html>


More information about the llvm-bugs mailing list