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: [email protected]
          Reporter: [email protected]
                CC: [email protected]

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,@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,@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,@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,@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.
_______________________________________________
llvm-bugs mailing list
[email protected]
https://lists.llvm.org/cgi-bin/mailman/listinfo/llvm-bugs

Reply via email to