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

Compiler incorrectly optimizes implicit cast to pointer expression (int32)(uint16+constant) to within expression ((int32)uint16+constant)

    • Icon: Bug Bug
    • Resolution: Unresolved
    • Icon: Medium Medium
    • Code Generation Tools
    • CODEGEN-12562
    • Hide
      C2000_16.9.0.LTS
      C2000_18.1.0.LTS
      C2000_22.6.0.LTS
      C2000_15.12.0.LTS
      C2000_6.4.0
      C2000_21.6.0.LTS
      C2000_18.12.0.LTS
      Show
      C2000_16.9.0.LTS C2000_18.1.0.LTS C2000_22.6.0.LTS C2000_15.12.0.LTS C2000_6.4.0 C2000_21.6.0.LTS C2000_18.12.0.LTS
    • Hide
      C2000_25.3.0.LTS*
      C2000_22.6.3.LTS*
      C2000_21.6.2.LTS*
      Show
      C2000_25.3.0.LTS* C2000_22.6.3.LTS* C2000_21.6.2.LTS*
    • default
    • Hide
      Use --opt_level=1 or lower
      Show
      Use --opt_level=1 or lower

      For pointer expressions with an unsigned 16bit int variable plus/minus a
      constant, eg: (uint16 + k), that also have an implicit cast to 32bit signed
      int, eg: (int32)(uint16 + k), the optimizer will incorrectly push the
      cast to within the expression: ((int32)uint16 + k)

      With option, --opt_level=2, this C code:

      MyStruct *struct = MyStructPtrs[uint16 - constant];
      

      Incorrectly optimizes to below:

      ; StructPtr = MyStructPtrs[(long)MyStructID+22284];
              MOV       ACC,AL << 1           ; [CPU_ALU] |24| 
              ADDL      ACC,@||MyStructPtrs|| ; [CPU_ALU] |24| 
              MOVL      XAR5,ACC              ; [CPU_ALU] |24| 
              MOVL      XAR0,#44568           ; [CPU_ALU] |24| 
              MOVL      ACC,*+XAR5[AR0]       ; [CPU_ALU] |24| 
              MOVL      *-SP[6],ACC           ; [CPU_ALU] |24| 
      

      And here's what should be generated instead:

      ; StructPtr = MyStructPtrs[(long)(MyStructID+22284u)];
              MOV       AL,#22284             ; [CPU_ALU] |24| 
              ADD       AL,*-SP[13]           ; [CPU_ALU] |24| 
              MOV       ACC,AL << 1           ; [CPU_ALU] |24| 
              ADDL      ACC,@||MyStructPtrs|| ; [CPU_ALU] |24| 
              MOVL      XAR5,ACC              ; [CPU_ALU] |24| 
              MOVL      ACC,*+XAR5[0]         ; [CPU_ALU] |24| 
              MOVL      *-SP[6],ACC           ; [CPU_ALU] |24| 
      

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

              Created:
              Updated: