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

CLA float pt ternary expressions returning negation may generate invalid results at --opt_level=2 or higher

XMLWordPrintable

    • Icon: Bug Bug
    • Resolution: Fixed
    • Icon: Medium Medium
    • Code Generation Tools
    • CODEGEN-10915
    • 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
      C2000_20.2.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 C2000_20.2.0.LTS
    • Hide
      C2000_22.6.1.LTS*
      C2000_21.6.2.LTS*
      Show
      C2000_22.6.1.LTS* C2000_21.6.2.LTS*
    • default
    • Hide
      Change code from using ternary operator to instead use if/then (and confirm generated assembly did not predicate MNEGF32 with conditional execution).

      Or compile at --opt_level=1 or lower to avoid if-conversion optimization.
      Show
      Change code from using ternary operator to instead use if/then (and confirm generated assembly did not predicate MNEGF32 with conditional execution). Or compile at --opt_level=1 or lower to avoid if-conversion optimization.

      CLA floating point ternary expressions returning negation may generate invalid results for --opt_level=2 or higher when if-conversion optimization is triggered.

      Below example code generates incorrect results when compiled at --opt_level=2 or higher
      and if-conversion optimization is triggered:
          res[0] = (p > n) ?  p : -n;   
          res[0] = (p > n) ? -p :  n;  
      Below if/then cases instead generate correct code due to not if-converting:
         if (p>n) res[0] =  p; else res[0] = -n; 
         if (p>n) res[0] = -p; else res[0] =  n; 

      No errors with below assembly without if-conversion:

      ;*** 10    -----------------------    p = a;
      ;*** 18    -----------------------    C$1 = b;
      ;*** 18    -----------------------    if ( p > C$1 ) goto g3;
              MMOV32    MR0,@a 
              MMOV32    MR1,@b  
              MCMPF32   MR0,MR1 
              MNOP 
              MNOP 
              MNOP 
              MBCNDD    $C$L1,GT 
              MNOP 
              MNOP 
              MNOP 

      Bug occurs with below assembly with if-conversion conditional execution:

      ;*** 10    -----------------------    p = a;
      ;*** 12    -----------------------    C$2 = b;
      ;*** 12    -----------------------    (p > C$2) ? (S$1 = p) : (S$1 = -C$2);
      ;*** 12    -----------------------    res[0] = S$1;
      ;***      -----------------------    return;
              MMOV32    MR0,@a   
              MMOV32    MR1,@b   
              MCMPF32   MR0,MR1  
              MNEGF32   MR0,MR1,LEQ ; conditional execution from if-conversion 
              MMOV32    @res,MR0   
              MNOP    
              MNOP  

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

              Created:
              Updated:
              Resolved: