IBM Support

IV75969: O3 WITH DISABLED INLINING CAUSING INCORRECT BRANCH

Subscribe

You can track all active APARs for this component.

APAR status

  • Closed as program error.

Error description

  • When compiling at optimization level -O3 and code inlining
    disabled (i.e. -qnoinline), a nested IF statement is incorrectly
    evaluated, and incorrect behaviour is seen.
    
    
    
       === TEST CASE ===
    
    #include <stdio.h>
    
    
    #define is_bit_set(x,y) ((x) & (y))
    
    #define L1 (unsigned short) 0x01
    #define L2 (unsigned short) 0x10
    #define L3 (unsigned short) 0x80
    #define L4 (unsigned short) 0x100
    
    #define NL1 (unsigned int) 0x01
    #define NL2 (unsigned int) 0x08
    #define NL3 (unsigned int) 0x40
    #define NL4 (unsigned int) 0x04
    
    #define NL2_L3 (NL2 | NL3)
    
    unsigned int set_flag(unsigned short inflags, unsigned int
    newflags)
    {
     unsigned int localflags = newflags;    // newflags=0x01
    
     if (is_bit_set(inflags, L1))           // inflags=0x191
     {
      if ((localflags & NL2_L3) == 0)   // this IF is failing at O3
      {
       if (is_bit_set(inflags, L2))
        localflags |= NL2;
       if (is_bit_set(inflags, L3))
        localflags |= NL3;
      }
      if ((localflags & (NL4)) == 0)
      {
       if (is_bit_set(inflags, L4))
        localflags |= NL4;
      }
     }
     else
     {
      if ((localflags & NL2_L3) == 0)
       localflags |= 0xFF;
     }
    
     return localflags;
    }
    
    int main()
    {
     unsigned short inflags = L1|L2|L3|L4;
     unsigned int newflags;
    
     newflags = set_flag(inflags, NL1); /* set_flag(0x191, 0x1); */
     printf("inflags 0x%x newflags 0x%x\n", inflags, newflags);
    
    }
    
    
    ===> INCORRECT OUTPUT:
    $ xlc -O3 -qnoinline apar.c
    $ ./a.out
    inflags 0x191 newflags 0x5
    
    
    ===> CORRECT OUTPUT
    $ xlc -O3 -qinline apar.c
    $ ./a.out
    inflags 0x191 newflags 0x4d
    

Local fix

  • Ensure that -qinline is used
    

Problem summary

  • PROBLEM DESCRIPTION:
    When inlining is disabled at optimization level -O3, a code
    optimization performed does not fully check if a condition
    register is live before introducing a new optimized
    instruction, which then overwrites it.
    
    USERS AFFECTED:
    Users using -O3 and -qnoinline .
    

Problem conclusion

  • The condition register is now checked correctly and the problem
    is fixed.
    

Temporary fix

Comments

APAR Information

  • APAR number

    IV75969

  • Reported component name

    XL C/C++ FOR AI

  • Reported component ID

    5725C7200

  • Reported release

    C10

  • Status

    CLOSED PER

  • PE

    NoPE

  • HIPER

    NoHIPER

  • Special Attention

    NoSpecatt

  • Submitted date

    2015-08-12

  • Closed date

    2015-10-14

  • Last modified date

    2015-10-14

  • APAR is sysrouted FROM one or more of the following:

  • APAR is sysrouted TO one or more of the following:

Fix information

  • Fixed component name

    XL C FOR AIX

  • Fixed component ID

    5725C7100

Applicable component levels

  • RC10 PSY

       UP



Document information

More support for: XL C for AIX
Compiler

Software version: 12.1

Reference #: IV75969

Modified date: 14 October 2015