[llvm-bugs] [Bug 38986] New: Poor code generation for masked scalar store

via llvm-bugs llvm-bugs at lists.llvm.org
Tue Sep 18 14:50:32 PDT 2018


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

            Bug ID: 38986
           Summary: Poor code generation for masked scalar store
           Product: libraries
           Version: trunk
          Hardware: PC
                OS: Linux
            Status: NEW
          Severity: enhancement
          Priority: P
         Component: Backend: X86
          Assignee: unassignedbugs at nondot.org
          Reporter: listmail at philipreames.com
                CC: llvm-bugs at lists.llvm.org

We allow the spelling of predicated scalar stores using the masked.load
intrinsic (by loading a <1 x Y> vector>), but the code generation for such is
terrible.  The odd part is the terrible bits don't appear length specific.

$ cat masked-scalar.ll

declare <1 x i32>  @llvm.masked.load.v1i32.p0v1i32 (<1 x i32>*, i32, <1 x i1>,
<1 x i32>)

define i32 @test(i1 %c, i32* %p) {
 %vc = insertelement <1 x i1> undef, i1 %c, i32 0
 %vp = bitcast i32* %p to <1 x i32>*
 %L = call <1 x i32> @llvm.masked.load.v1i32.p0v1i32 (<1 x i32>* %vp, i32 4, <1
x i1> %vc, <1 x i32> undef)
 %ret = bitcast <1 x i32> %L to i32
 ret i32 %ret
}

define i32 @test2(i1 %c, i32* %p) {
  br i1 %c, label %taken, label %untaken
taken:
  %v = load i32, i32* %p
  ret i32 %v
untaken:
  ret i32 undef
}

$ ../build/bin/opt -O3 -S masked-scalar.ll | ../build/bin/llc -O3 -mcpu=skylake
        .text
        .file   "masked-scalar.ll"
        .globl  test                    # -- Begin function test
        .p2align        4, 0x90
        .type   test, at function
test:                                   # @test
# %bb.0:
        andb    $1, %dil
        movl    %edi, %eax
        negb    %al
                                        # implicit-def: $ecx
        testb   %dil, %dil
        jne     .LBB0_1
# %bb.2:                                # %else
        testb   $1, %al
        cmovnel %ecx, %eax
        retq
.LBB0_1:                                # %cond.load
        movl    (%rsi), %ecx
        testb   $1, %al
        cmovnel %ecx, %eax
        retq
.Lfunc_end0:
        .size   test, .Lfunc_end0-test
                                        # -- End function
        .globl  test2                   # -- Begin function test2
        .p2align        4, 0x90
        .type   test2, at function
test2:                                  # @test2
# %bb.0:
        testb   $1, %dil
                                        # implicit-def: $eax
                                        # implicit-def: $ax
                                        # implicit-def: $al
                                        # implicit-def: $ah
                                        # implicit-def: $hax
        je      .LBB1_2
# %bb.1:                                # %taken
        movl    (%rsi), %eax
.LBB1_2:                                # %untaken
        retq
.Lfunc_end1:
        .size   test2, .Lfunc_end1-test2
                                        # -- End function

        .section        ".note.GNU-stack","", at progbits

Observations:
1) We should be able to use a simple test/je for the i1 vector test.  
2) We don't need the cmovs at all since we're selecting with undef.

-- 
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/20180918/875d2f9e/attachment.html>


More information about the llvm-bugs mailing list