Skip to content

-fno-slp-vectorize only works if placed after -O2/-O3, unlike GCC #160633

@dongjianqiang2

Description

@dongjianqiang2

When using Clang, the effect of -fno-slp-vectorize depends on its ordering relative to optimization level flags like -O2 or -O3.

Clang behavior:

# Case 1: disable flag before -O2
clang -fno-slp-vectorize -O2 test.c -S -o -
# => SLP vectorization still happens

# Case 2: disable flag after -O2
clang -O2 -fno-slp-vectorize test.c -S -o -
# => SLP is disabled as expected

The reason is that -O2 re-enables its implied optimizations (including -fslp-vectorize) after earlier flags, so the last one wins.

GCC behavior:
In GCC, the corresponding option is -f(no-)tree-slp-vectorize.

gcc -fno-tree-slp-vectorize -O2 test.c -S -o -
gcc -O2 -fno-tree-slp-vectorize test.c -S -o -

In both cases, SLP vectorization is disabled. GCC treats the explicit -fno- as an override, independent of ordering.

Why this is confusing:
Users migrating from GCC expect -fno-slp-vectorize to always disable SLP, regardless of its order relative to -O2.
In Clang, putting the flag before -O2 silently fails to disable SLP, which can cause unexpected results in build systems where flag ordering is not obvious.

Possible solutions:
Align with GCC: make explicit -fno-slp-vectorize override optimization levels regardless of order.

Reproducer:
Minimal example: Godbolt link

Metadata

Metadata

Assignees

Labels

clang:driver'clang' and 'clang++' user-facing binaries. Not 'clang-cl'

Type

No type

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions