Intel® C++ Compiler
Community support and assistance for creating C++ code that runs on platforms based on Intel® processors.
Announcements
The Intel sign-in experience has changed to support enhanced security controls. If you sign in, click here for more information.
7782 Discussions

Optimization bug which can lead to access violation

OTorg
New Contributor III
168 Views

Hello!

I compiled the x264 project with Intel Compiler 15.0, windows, x86, and found the buggy-generated code at O2/O3 optimization level.

static float predict_row_size( x264_t *h, int y, float qscale )
{
    x264_ratecontrol_t *rc = h->rc;
    float pred_s = predict_size( &rc->row_pred[0], qscale, h->fdec->i_row_satd );
    if( h->sh.i_type == SLICE_TYPE_I || qscale >= h->fref[0][0]->f_row_qscale )
    {
        if( h->sh.i_type == SLICE_TYPE_P
            && h->fref[0][0]->i_type == h->fdec->i_type
            && h->fref[0][0]->f_row_qscale > 0
            && h->fref[0][0]->i_row_satd > 0
            && (abs(h->fref[0][0]->i_row_satd - h->fdec->i_row_satd) < h->fdec->i_row_satd/2))
        {
            float pred_t = h->fref[0][0]->i_row_bits * h->fdec->i_row_satd / h->fref[0][0]->i_row_satd
                         * h->fref[0][0]->f_row_qscale / qscale;
            return (pred_s + pred_t) * 0.5f;
        }
        return pred_s;
    }
    else
    {
        float pred_intra = predict_size( &rc->row_pred[1], qscale, h->fdec->i_row_satds[0][0] );
        return pred_intra + pred_s;
    }
}

Inspecting the generated asm, you can see that "h->fref[0][0]->i_type" value is read from memory (for the purpose to store it on stack) BEFORE executing "h->sh.i_type == SLICE_TYPE_I" condition. But "h->fref[0][0]" is NULL when "h->sh.i_type == SLICE_TYPE_I", which leads to access violation.

I can publish more details about build parameters and command line for resulting executable run with crash, if need.

0 Kudos
1 Solution
Shenghong_G_Intel
168 Views

FYI. This issue is fixed in v15.0 update 2 (w_ccompxe_2015.2.179.exe). I've verified the fix and it works now.

Thanks,

Shenghong

View solution in original post

6 Replies
Shenghong_G_Intel
168 Views

Hi dj_alek,

yes, do publish more details (download link/version of x264, how to build, how to run the executable which will crash, version of compiler etc.) I will have a try to see whether I can reproduce the issue and submit to developer to fix. Thank you very much.

Thanks,

Shenghong

OTorg
New Contributor III
168 Views

steps to reproduce the problem:

1. we need machine with microsoft visual studio 2010 or 2013 (c/c++) + intel compiler 14 or 15

2. files to download:
2.1. x264 source code: https://drive.google.com/file/d/0B8SCkOT4os4HMmF5eXRwTGlFbVE/view?usp=sharing
2.2. test requisites: https://drive.google.com/file/d/0B8SCkOT4os4Hc04zWmNyd1p2VWM/view?usp=sharing
2.3. build tools (mingw's msys + yasm): https://drive.google.com/file/d/0B8SCkOT4os4HNm9vNDM2cGhHX0E/view?usp=sharing

3. unpack downloaded archives into e.g C:\x264src, C:\test, C:\mgw_msys

4. run icl command line environment for ia32, e.g: "*\Start Menu\*\Intel Parallel Studio XE 2013\Command prompt\Parallel Studio XE with Intel Compiler XE v14.0 Update 3\IA-32 Visual Studio 2010 mode.lnk"

5. inside that cmdline:
5.1. run "C:\mgw_msys\msys.bat"
5.2. go to the source folder: "cd C:/x264src"
5.3. run "CC=icl configure --enable-debug --extra-cflags=-Zp8 --disable-gpl --enable-win32thread --disable-opencl --disable-avs --disable-swscale --disable-lavf --disable-ffms --disable-gpac --disable-lsmash"
5.4. run "make"
5.5. exit

6. copy builded x264.exe from C:\x264src to C:\test

7. check x264.exe works: run "C:\test\_ok.bat", which should make result.mkv, which can be played with e.g media player classic

8. and now start x264.exe with parameters that utilize buggy-compiled code: "C:\test\_av.bat", which leads to access violation

Shenghong_G_Intel
168 Views

Hi dj_alek,

Thank you for providing these details, I have been able to reproduce the issue based on the steps (Intel Compiler v15). The issue also exists with O1.

I will report it to dev team to fix.

Thanks,

Shenghong

Shenghong_G_Intel
168 Views

I have submitted the issue to developer to fix, the issue happens when compiler is trying to vectorize the loop.

By the way, you may workaround it by adding "#pragma optimization_level 0" before function predict_row_size to disable the optimization for this function only as a workaround.

Thanks,

Shenghong

OTorg
New Contributor III
168 Views

Thank you.

I have already found and use workaround: add "__declspec(noinline)" before "static float predict_row_size( x264_t *h, int y, float qscale )"

Shenghong_G_Intel
169 Views

FYI. This issue is fixed in v15.0 update 2 (w_ccompxe_2015.2.179.exe). I've verified the fix and it works now.

Thanks,

Shenghong

Reply