Intel® C++ Compiler
Community support and assistance for creating C++ code that runs on platforms based on Intel® processors.
7953 Discussions

How to remove some useless condition branch by using some optimization options

applemax82
Beginner
315 Views

Hi,

I used icc to build some projects, such as ffmpeg. I disabled all compiler's optimization by using '-O0' instead of '-O3', but icc reported some error as shown below:

Part of source code is:

#define ARCH_ARM 0

    if (ARCH_ARM)
        ff_float_dsp_init_arm(fdsp);

Error messages are shown as follow:

libavutil/libavutil.a(float_dsp.o): In function `avpriv_float_dsp_init':
/export/qiang/sourceCode/ffmpeg-2.8.3/libavutil/float_dsp.c:132: undefined reference to `ff_float_dsp_init_aarch64'
/export/qiang/sourceCode/ffmpeg-2.8.3/libavutil/float_dsp.c:134: undefined reference to `ff_float_dsp_init_arm'
/export/qiang/sourceCode/ffmpeg-2.8.3/libavutil/float_dsp.c:136: undefined reference to `ff_float_dsp_init_ppc'
/export/qiang/sourceCode/ffmpeg-2.8.3/libavutil/float_dsp.c:140: undefined reference to `ff_float_dsp_init_mips'
 

If '-O3' is used, the above error messages don't exist. I want to disable all optimization options and remove useless condition branch. Which icc option is only used to remove useless condition?

The icc information is shown as follow:

Intel(R) C Intel(R) 64 Compiler XE for applications running on Intel(R) 64, Version 14.0.2.144 Build 20140120
Copyright (C) 1985-2014 Intel Corporation.  All rights reserved.
 

Thanks!

 

0 Kudos
3 Replies
TimP
Honored Contributor III
315 Views

It looks like you would need to guard that section with #if ARCH_ARM .... #endif to avoid having the dead code elimination depend on optimization level.  At -O0 there probably isn't enough analysis of possible code paths to accomplish dead code elimination on that basis.

I would have thought that -O1 or  -Os would eliminate such a branch, as we needed in the past to get icc to minimize code size.

0 Kudos
applemax82
Beginner
315 Views

Thanks for your quick response.

There is too much source code like:

#define ARCH_ARM 0

    if (ARCH_ARM)
        ff_float_dsp_init_arm(fdsp);

It will take too much time to replace conditional branch with ' #if ARCH_ARM .... #endif'. Does icc have some specific compiling option to roll out this sort of useless conditional branch?

0 Kudos
jimdempseyatthecove
Honored Contributor III
315 Views

An alternative is when NOT ARM architecture, is to supply your own dummy functions (that should never get called)

void ff_float_dsp_init_arm(...)
{
   printf("??? ff_float_dsp_init_arm called\n");
   exit(-1);
}

Do this as a separate .obj and place into a library.

When you build without dead code elimination then you will link in a function that should never be called.

When you build with dead code elimination, then the function will not be linked in.

Jim Dempsey

0 Kudos
Reply