Uploaded image for project: 'Embedded Software & Tools'
  1. Embedded Software & Tools
  2. EXT_EP-11012

Compiler generates incorrect code for 64-bit comparison against small constant, when --opt_level=3 or higher

XMLWordPrintable

    • Icon: Bug Bug
    • Resolution: Unresolved
    • Icon: Medium Medium

      The attachment [^file.c]has this function ...

      _Bool  pb_encode_varint(pb_ostream_t *stream, uint64_t value)
      {
          if (value <= 0x7F)
          {
              /* Fast path: single byte */
              pb_byte_t byte = (pb_byte_t)value;
              return pb_write(stream, &byte, 1);
          }
          else
          {
              return pb_encode_varint_32(stream, (uint32_t)value, (uint32_t)(value >> 32));
          }
      }
      

      Build it ...

      armcl -@options.txt file.c
      

      Inspect the resulting assembly file to see these lines near the start of the function ...

              MOV       V9, A1                ; [DPU_V7M3_PIPE] |97591| 
      	.dwpsn	file "file.c",line 97592,column 5,is_stmt,isa 1
              MOVS      V4, A4                ; [DPU_V7M3_PIPE] |97592| 
              IT        EQ                    ; [DPU_V7M3_PIPE] 
              CMPEQ     A3, #127              ; [DPU_V7M3_PIPE] |97592| 
              BHI       ||$C$L43||            ; [DPU_V7M3_PIPE] |97592|
      

      For the case seen by the customer, the call is ...

          pb_ostream_t stream = {0,0,0,0,0};
          uint64_t value = 0x200b162d74e5;
          if(pb_encode_varint(&stream, value))
      

      The value argument is much greater then 0x7f. So the BHI conditional branch should be taken. But it isn't.

      When built with --opt_level=2 or lower, the correct code is generated.

            syncuser TI User
            syncuser TI User
            Votes:
            0 Vote for this issue
            Watchers:
            4 Start watching this issue

              Created:
              Updated: