4

How to disable auto-vectorization (SSE2), globally or for a specific for loop, without reverting to /Od in MSVS 2010?

I've tried all 3 possible options for Enable Enhanced Instruction Set, including "Not set", to no avail.

P. S. Curiously, even /Od doesn't help.

Violet Giraffe
  • 32,368
  • 48
  • 194
  • 335
  • 2
    @DanielFischer: Why do I want to disable vectorization? For 2 reasons: to assess performance boost from using SSE2, and to allow for consistent and meaningful performance comparison with machines that do not have SSE. – Violet Giraffe Jan 17 '12 at 21:01
  • 2
    Perhaps the following might be relevant: http://stackoverflow.com/questions/1480916/how-do-i-enable-the-sse-sse2-instruction-set-in-visual-studio-2008-using-cmake – NPE Jan 17 '12 at 21:06
  • 1
    That makes tons of sense. Thanks for satisfying my curiosity. I wish I could reciprocate. – Daniel Fischer Jan 17 '12 at 21:08

5 Answers5

4

For a specific loop, you can add a pragma:

#pragma loop(no_vector) 

This is actually documented on MSDN (although I only found it there after I learned about it..)

If you don't like to add a pragma, you can choose to compile with /favor:ATOM. That is a bit of hack, but it will allow you to disable auto-vectorization, without touching the source, and still optimize for speed otherwise.

Alternatively there are the two optimization strategies /O1 "optimize size" and /Os "favor small code". Auto-vectorization generates substantially more code, so if you optimize for size, auto-vectorization is disabled.

I learned all this recently from by reading the auto-vectorization cookbook. See the last line of the section "Rules for the loop body".

Disclaimer: I am not actually using the VS2012 compiler yet (need to support Win XP), so I haven't tested this. Also, the compiler switches might work differently in 2013 or later.

  • Thanks for the link! BTW, have you seen there's a special vc11 runtime for XP? I believe that's how you can use 2012 compiler and runtime with XP. – Violet Giraffe Sep 14 '13 at 21:12
2

You can try the undocumented option- /d2Qvec- with the latest VS2022.

user1669844
  • 703
  • 9
  • 23
2

You could isolate your for loop in a separated function and try to use #pragma optimize for it:

// Disable all optimizations
#pragma optimize("", off)

// your function here

// Enable them back
#pragma optimize("", on)

... but this should have the same effect of /Od just on that particular function, so it may not help.

If you are compiling for x86 (and not x86_64, where it has no effect) you could also disable the SSE2 instruction set as a whole (removing the /arch:SSE2 option). Sadly, its granularity is limited to a whole source file.

Matteo Italia
  • 123,740
  • 17
  • 206
  • 299
  • Thanks, that ought to work - vectorization in /Od happens only in x64 (why?), but that's not exactly what I want since loop counter isn't even locked in a register in /Od. Performance impact will not only be due to vectorization. – Violet Giraffe Jan 17 '12 at 21:30
0

Try making sure that the /arch compiler option is not set.

zdan
  • 28,667
  • 7
  • 60
  • 71
0

Which compiler? AFAIK, VS will implement auto-vectorization starting from version 11. VS uses SSE instructions for floating-point, but it doesn't mean that it actually vectorizes loops.

zvrba
  • 24,186
  • 3
  • 55
  • 65