if i compile programs using ICC compiler with -xCORE-AVX2 and my cpu doesn't support AVX/AVX2, can it compile successfully?
if it compiles ok, can it run successfully?
The man of ICC CORE-AVX2 is "CORE-AVX2 May generate Intel(R) Advanced Vector Extensions 2 (Intel(R) AVX2), Intel(R) AVX, SSE4.2, SSE4.1, SSE3, SSE2, SSE, and SSSE3 instructions for Intel(R) processors.". I am not sure whether it compiles with AVX2 instructions.
It should compile successfully; however, compiler may generate AVX2 instructions and you will run into issue if you execute on the processors that aren't supported AVX2.
You should use -axCORE-AVX2 instead of -xCORE-AVX2
Pay attention that in my experience using -ax on the latest version (19.3) yields code that requires the added instructions and not only additional dispatched path.
For instance /arch:SSE3 /Qax:AVX yielded a code which doesn't work on Westmere / Nehalem while both support SSE4.2.
By default, the Intel compiler generates a set of run-time checks for all of the instruction sets that the compile line allows to be used in the executable. These checks are run as soon as the program is launched (i.e., before "main()"), and will cause the program to abort if the platform does not support all of the instruction sets that might be in the executable. For example, attempting to run a code compiled for "CORE-AVX512" on a Broadwell system gives the message:
Please verify that both the operating system and the processor support Intel(R) AVX512DQ, AVX512F, AVX512CD, AVX512BW and AVX512VL instructions.
If I recall correctly, the "-ffreestanding" compiler option removes these run-time checks, so that the executable will run until it hits an illegal instruction. If the execution does not run into any unsupported instructions, then it will execute normally. Note that the executable might still have illegal instructions, but if they are not on the path executed by a particular run, then they won't be seen.