[llvm-dev] Potentially unsafe loop optimization

Juneyoung Lee via llvm-dev llvm-dev at lists.llvm.org
Wed Feb 17 17:22:21 PST 2021


FWIW, clang 11.0 reproduces the bug: https://godbolt.org/z/GvoK63
But clang trunk doesn't: https://godbolt.org/z/bed7eM



On Thu, Feb 18, 2021 at 10:01 AM Craig Topper via llvm-dev <
llvm-dev at lists.llvm.org> wrote:

> I ran the IR through clang -O2 on godbolt and didn't get a return. So I
> think something is happening in the middle end?
>
> ~Craig
>
>
> On Wed, Feb 17, 2021 at 4:57 PM Johannes Doerfert <
> johannesdoerfert at gmail.com> wrote:
>
>> llc generates the return in all version I tried:
>> https://godbolt.org/z/oh3fqh
>>
>>
>> On 2/17/21 6:46 PM, Craig Topper wrote:
>> > What version of llvm are you using? Godbolt is showing trunk and llvm 10
>> > have a conditional branch, llvm 11 does not.
>> >
>> > ~Craig
>> >
>> >
>> > On Wed, Feb 17, 2021 at 4:41 PM Richard Kenner via llvm-dev <
>> > llvm-dev at lists.llvm.org> wrote:
>> >
>> >>> Long story short, from what I can see there is no miscompilation
>> >>> or change in semantics for that matter.
>> >> So why does the .s file not contain the loop exit test?
>> >>
>> >>          .text
>> >>          .file   "c26006a.adb"
>> >>          .globl  _ada_c26006a                    # -- Begin function
>> >> _ada_c26006a
>> >>          .p2align        4, 0x90
>> >>          .type   _ada_c26006a, at function
>> >> _ada_c26006a:                           # @_ada_c26006a
>> >>          .cfi_startproc
>> >> # %bb.0:                                # %entry
>> >>          pushq   %rbx
>> >>          .cfi_def_cfa_offset 16
>> >>          subq    $32, %rsp
>> >>          .cfi_def_cfa_offset 48
>> >>          .cfi_offset %rbx, -16
>> >>          movw    $8257, 16(%rsp)                 # imm = 0x2041
>> >>          movb    $49, 18(%rsp)
>> >>          movw    $8257, (%rsp)                   # imm = 0x2041
>> >>          movb    $50, 2(%rsp)
>> >>          xorl    %ebx, %ebx
>> >>          jmp     .LBB0_1
>> >>          .p2align        4, 0x90
>> >> .LBB0_3:                                # %loop.cond.iter
>> >>                                          #   in Loop: Header=BB0_1
>> Depth=1
>> >>          incb    %bl
>> >> .LBB0_1:                                # %loop.cond
>> >>                                          # =>This Inner Loop Header:
>> Depth=1
>> >>          movb    %bl, 17(%rsp)
>> >>          movb    %bl, 1(%rsp)
>> >>          movzwl  (%rsp), %eax
>> >>          xorw    16(%rsp), %ax
>> >>          movzbl  2(%rsp), %ecx
>> >>          xorb    18(%rsp), %cl
>> >>          movzbl  %cl, %ecx
>> >>          orw     %ax, %cx
>> >>          jne     .LBB0_3
>> >> # %bb.2:                                #   in Loop: Header=BB0_1
>> Depth=1
>> >>          callq   abort
>> >>          jmp     .LBB0_3
>> >> .Lfunc_end0:
>> >>          .size   _ada_c26006a, .Lfunc_end0-_ada_c26006a
>> >>          .cfi_endproc
>> >>                                          # -- End function
>> >>          .section        ".note.GNU-stack","", at progbits
>> >> _______________________________________________
>> >> LLVM Developers mailing list
>> >> llvm-dev at lists.llvm.org
>> >> https://lists.llvm.org/cgi-bin/mailman/listinfo/llvm-dev
>> >>
>>
> _______________________________________________
> LLVM Developers mailing list
> llvm-dev at lists.llvm.org
> https://lists.llvm.org/cgi-bin/mailman/listinfo/llvm-dev
>


-- 

Juneyoung Lee
Software Foundation Lab, Seoul National University
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.llvm.org/pipermail/llvm-dev/attachments/20210218/b9d2cff2/attachment.html>


More information about the llvm-dev mailing list