This thread has been locked.

If you have a related question, please click the "Ask a related question" button in the top right corner. The newly created question will be automatically linked to this question.

Compiler/AM5728: IF condition is not wroking properly with optimization enabled.

Part Number: AM5728

Tool/software: TI C/C++ Compiler

Hi , 

I am facing  a problem where if condition is not working properly  when in the optimization enabled but same code works fine in the optimization is off.

 for (k_index = 0; k_index < m_size1; k_index++) {
        s_float = Array[k_index][0];
        for (l_index = 1; l_index < n_size2; l_index++)
        {
            if ( Array[k_index][l_index] < s_float)
            {
                s_float = Array[k_index][l_index];
            }
        }

}

in the above  if ( Array[k_index][l_index] < s_float)  is not working properly , Array[k_index][l_index] is greater than s_float , still it is saying Array[k_index][l_index]  smaller than s_float.

Regards

R D Nadaf

  • For the source file with the problem, please follow the directions in the article How to Submit a Compiler Test Case.  After creating the preprocessed file, please add a comment just before the problem comparison similar to ...

    // PROBLEM HERE
    // Works when written:
    // <code here>

    In addition, what are the values of each operand to the comparison that works incorrectly?

    Thanks and regards,

    -George

  • HI George , 

        Thanks for your reply, 

    In function void hungarian_new_float(int size1, int size2, float Array[size1][size2], char Result[size1][size2]) in optimized enalbed with -O3.

    there is if a condition is not working properly ,  that code looks like this.

    for (k_index = 0; k_index < m_size1; k_index++) {
            s_float = Array[k_index][0];
            for (l_index = 1; l_index < n_size2; l_index++)
                if (Array[k_index][l_index] < s_float)              // Even  Array[k_index][l_index] is less greater than  s_float , but  it is saying   Array[k_index][l_index] is lower.
                    s_float = Array[k_index][l_index];

    but if you make small change  like as follows

    float ak1 ;

    for (k_index = 0; k_index < m_size1; k_index++) {

            s_float = Array[k_index][0];
            for (l_index = 1; l_index < n_size2; l_index++) {
              ak1 = Array[k_index][l_index];                                                     // in this case it is working fine .

    if (ak1  < s_float)             

                    s_float = Array[k_index][l_index];

    }

    Regards,

    R  D Nadaf

  • HI George ,
    the compiler version is <TI V8.2.2.>
    Values for which it is not working as follows,
    the matrix is 3 x 3 , and values are
    +infinity , .029082903, 7.95e-5
    .00905365310, + infinity , + infinity
    ,0, 0 , 0
    in this for first row smallest value is 7.95e-5 and code is giving that only but for 2nd row smallest value is .00905365310 but code is giving +infinity . so when if condition is comparing +infinity with .00905365310 , it is saying +infinity is smaller , this is problem we are facing.

    Regards,
    R D Nadaf
  • I apologize, but I cannot seem to figure this one out.  Is it practical for you to supply a CCS project which can be executed, and see the wrong result?  If so, please zip up that project as described in the article Sharing Projects.  Then attach the zip file to your next post.

    Or, you can send me the project privately.  Hover your mouse over my name or avatar. A box will pop up. Click on Send a private message. In the message compose interface which comes up, use the paper clip icon to attach the zip file.

    Thanks and regards,

    -George

  • Is it practical for you to supply the requested CCS project?

    Thanks and regards,

    -George

  • Hi George , 

         I don't have permission to  send  the entire project , I have checked the assembly code observed that there is some cache problem , some memory corruption is happening there. If you check that buffer in the memory browser  values  different when L1DCache is enabled and Disabled , is there a way to fix this problem .

    With L1DCache disable 

    So if condition is not comparing the proper values , it is comparing some different values and gives the results based on that, so please suggest how to fix this problem.

    Regards,

    R D Nadaf

     

  • Nadaf,

    Do you use AM57x PSDK Linux, RTOS, Android, bare metal SW or else?

    Do you use AM572x TI board (EVM, X15, IDK) or custom board?

    Do you run your code on Cortex-A15 MPU or C66x DSP?

    Regards,
    Pavel

  • Hi Pavel ,

     Sorry for the delayed reply , we are  using.

    *   AM57XX   and processor_sdk_rtos_am57xx_5_02_00_10  .

    *   This is custom board.

    *  We are running code on C66x DSP  .

    Regards

    R  D Nadaf

  • Hi,

    Even you can't provide a CCS project, can you send us info:

    L1DCFG setup

    L2CFG setup

    L1PCFG setup

    Where you code run? L2? DDR3? What is the cache setup? 

    Can you provide you linker command file?

    What is the CGT version?

    What is the compiler option to show.not show this problem?  

     void hungarian_new_float(int size1, int size2, float Array[size1][size2], char Result[size1][size2]) in optimized enalbed with -O3.========> Is this TI code or you code?

    Are you able to send us a small CCS project showing the issue? Then we can try to reproduce.

    Regards, Eric 

  • Hi  Eric, 

     I have created the Unit test project , there also the IF condition is failing , please find the attachment.

    /cfs-file/__key/communityserver-discussions-components-files/791/Hangarain.7z

    Regards,

    R D Nadaf

  • Hi,

    Thanks for providing the CCS project.

    I saw the compiler option is: "C:/ti/ccs_8_3_0/ccsv8/tools/compiler/ti-cgt-c6000_8.2.5/bin/cl6x" -mv6600 --include_path="C:/Project/AM57_Floating/Hangarain" --include_path="C:/ti/ccs_8_3_0/ccsv8/tools/compiler/ti-cgt-c6000_8.2.5/include" --define=BUILD_AM572X_DSP --define=SOC_AM572x -g --diag_warning=225 --diag_wrap=off --display_error_number --preproc_with_compile --preproc_dependency="hungarian_new_float_with_wrapper.d_raw" --cmd_file="configPkg/compiler.opt" "../hungarian_new_float_with_wrapper.c"

    There is no -O3 optimization.

    When I run the test, I got something printed from the CCS console:

    [C66xx_DSP1] Array[k_index][l_index] < (row_dec_float[k_index] - col_inc_float[l_index])
    0.000000 < (0.000000 - 0.000000)

    I knew that L1DCFG = 4, that is 32KB cache.

    Did this reproduce your issue? 

    Then I modified L1DCFG  = 0, that is 0KB cache. I got the same CIO console output. So I am not sure what is the indication of issue reproduced and how you disable L1D and made the difference?  

    Regards, Eric

  • Hi Eric, 

          In the shared code , in the function  void hungarian_new_float(int size1, int size2, float Array[size1][size2], char Result[size1][size2]), line no 82, 

        for (k_index = 0; k_index < m_size1; k_index++) {
            s_float = Array[k_index][0];
            for (l_index = 1; l_index < n_size2; l_index++)
                if (Array[k_index][l_index] < s_float)
                    s_float = Array[k_index][l_index];

     

    In the above loop  , for  k_index  = 1 , if condition is failing . We are passing a matrix to this function , incase of first row  values are  3, 1, 5 and if condition is working fine , it gives 1 as the lowest in the row.

    But for the second row , values are 3, 2, 7  but if condition is saying 7 is lowest instead of 2  , this is the problem we are facing , we can add system_printf  and we can print the results there.

     

    Regards,

    R  D Nadaf

     

     

  • Hi,

    Thanks for explanation! I was able to reproduce the issue, however, I don't see any L1D setting caused the problem. But I believe it is a compiler issue and I asked my colleague to follow up.

    Below summarized what I tried:

    - I used TI CGT 8.2.2 as customer 

    - I compiled code without any optimization 

    -mv6600 -Ooff --include_path="C:/Project/AM57_Floating/Hangarain" --include_path="C:/ti/ti-cgt-c6000_8.2.2/include" --define=BUILD_AM572X_DSP --define=SOC_AM572x -g --diag_warning=225 --diag_wrap=off --display_error_number

    There is a 3x3 floating point array passing into processing, below is the initialization value

    cost_matrix_float_allowed_extended[0][0] = 3;
    cost_matrix_float_allowed_extended[0][1] = 1;
    cost_matrix_float_allowed_extended[0][2] = 5;

    cost_matrix_float_allowed_extended[1][0] = 3; //2;
    cost_matrix_float_allowed_extended[1][1] = 2;
    cost_matrix_float_allowed_extended[1][2] = 7; //8;

    cost_matrix_float_allowed_extended[2][0] = 1; //2; //0;
    cost_matrix_float_allowed_extended[2][1] = 1; //2; // 0;
    cost_matrix_float_allowed_extended[2][2] = 1; //2; //0;

    Before finding the minimum, the array was changed to:

    [2.0, 0.0, 4.0,

    2.0, 1.0, 6.0,

    0.0, 0.0, 0.,0]

    Then the minimum is searched in each row, the results is saved into line 87:  row_dec_float[k_index] = s_float;  where s_float is the minimum

    The expected results are: 0.0, 1.0, 0.0. 

    With L1DCFG (0x0184_0040 = 0x4, 32KB cache), I saw results 0.0, 6.0, 0.0.

    With L1DCFG = 0, No cache, I still saw results 0.0, 6.0, 0.0.

    Regards, Eric

  • Part Number: AM5728

    Tool/software: TI C/C++ Compiler

    Hi,

    Is there any update regarding the if condition Failure case mentioned in the following query.

    Regards

    Asha

  • Asha,

    Sorry for the late! I looped in our C6000 compiler team for the help!

    Regards, Eric

  • Thank you for the test case.  I can reproduce the problem.  I filed the entry CODEGEN-6409 in the SDOWP system to have this investigated.  You are welcome to follow it with the SDOWP link below in my signature.

    Thanks and regards,

    -George