https://bugs.llvm.org/show_bug.cgi?id=50682
Bug ID: 50682
Summary: Clang doesn't honor unroll #pragma to disable loop
unrolling
Product: clang
Version: trunk
Hardware: PC
OS: Linux
Status: NEW
Severity: enhancement
Priority: P
Component: -New Bugs
Assignee: [email protected]
Reporter: [email protected]
CC: [email protected], [email protected],
[email protected], [email protected]
Clang doesn't honor unroll #pragma to disable loop unrolling. I tried the
following 3 approaches to disable loop unrolling, but it's never honored. The
code is always autovectorized and unrolled regardless of #pragmas used.
Is there any way to make clang not unroll loops? Because in many cases I know
the loops will have very few iterations and I mark them with compiler specific
pragmas to not unroll, however, clang doesn't really honor them.
Compile flags:
-O2 -fno-math-errno -mavx2 -std=c++2a
The problem happens with -O2, -O3, and even -Os.
Sample code:
#include <stdint.h>
uint32_t countBits1(uint32_t* x, uint32_t n) {
uint32_t count = 0;
#pragma clang loop unroll(disable)
for (uint32_t i = 0; i < n; i++) {
count += __builtin_popcount(x[i]);
}
return count;
}
uint32_t countBits2(uint32_t* x, uint32_t n) {
uint32_t count = 0;
#pragma nounroll
for (uint32_t i = 0; i < n; i++) {
count += __builtin_popcount(x[i]);
}
return count;
}
uint32_t countBits3(uint32_t* x, uint32_t n) {
uint32_t count = 0;
#pragma unroll(1)
for (uint32_t i = 0; i < n; i++) {
count += __builtin_popcount(x[i]);
}
return count;
}
Compile explorer:
https://godbolt.org/z/EcoGqoaYG
--
You are receiving this mail because:
You are on the CC list for the bug._______________________________________________
llvm-bugs mailing list
[email protected]
https://lists.llvm.org/cgi-bin/mailman/listinfo/llvm-bugs