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

An inlined cast from int32_t to float32_t may get an incorrect optimization

XMLWordPrintable

    • Icon: Bug Bug
    • Resolution: Unresolved
    • Icon: Medium Medium
    • Code Generation Tools
    • CODEGEN-12270
    • Hide
      C2000_22.6.0.LTS
      C2000_22.6.1.LTS
      C2000_18.12.2.LTS
      C2000_21.6.0.LTS
      C2000_20.2.0.LTS
      Show
      C2000_22.6.0.LTS C2000_22.6.1.LTS C2000_18.12.2.LTS C2000_21.6.0.LTS C2000_20.2.0.LTS
    • Hide
      C2000_22.6.2.LTS*
      C2000_NEXT*
      C2000_21.6.2.LTS*
      Show
      C2000_22.6.2.LTS* C2000_NEXT* C2000_21.6.2.LTS*
    • default
    • Hide
      For the example case in description, replacing the inlined call to ftol() with a cast to float32_t was enough to avoid the bug. Also, encountering the bug depends on the right code shape and context in order for the incorrect optimization to be used:

      From this:
          float32_t flt = ftol(global_int32);
      to this:
          float32_t flt = (float32_t)global_int32;
      Show
      For the example case in description, replacing the inlined call to ftol() with a cast to float32_t was enough to avoid the bug. Also, encountering the bug depends on the right code shape and context in order for the incorrect optimization to be used: From this:     float32_t flt = ftol(global_int32); to this:     float32_t flt = (float32_t)global_int32;

      An inlined cast from int32_t to float32_t may get an incorrect optimization.

      For below cutdown C code:

      inline static float32_t ftol(int32_t input){
        return (float32_t)input;
      }
      void foo() 
      {
          global_int32 = bar(...);
          ... more code needed for context
          float32_t flt = ftol(global_int32);
      }
      

      The correct generated assembly should be:

              MOVL      XAR4,#3671270        
              ...
              MOVL      XAR4,*+XAR4[0]      
              ...
              MOV32     R0H,XAR4 
              ...
              MOVL      @||global_int32||,XAR4 
              ...
              I32TOF32  R0H,R0H      
              ...
              MOV32     @||flt||,R0H  
      

      However, an incorrect optimization may generate below which is invalid since the memory load was based on XAR4 which is the same register:

              MOVL      XAR4,#3671270 
              ...
              MOVL      XAR4,*+XAR4[0]
              ...
              MOVL      @||global_int32||,XAR4 
              ...
              MOV32     R0H,*+XAR4[0]  ; <--- incorrect
            ; above should be:  MOV32 R0H,XAR4
              ...
              I32TOF32  R0H,R0H        
              ...
              MOV32     @||flt||,R0H
      

      Above incorrect optimization can run with --opt_level=off,0,1,2,3,4

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

              Created:
              Updated: