[llvm-bugs] [Bug 48167] New: If "#pragma clang loop interleave_count(3)" is specified for the loop, it is ignored.
via llvm-bugs
llvm-bugs at lists.llvm.org
Fri Nov 13 02:45:48 PST 2020
https://bugs.llvm.org/show_bug.cgi?id=48167
Bug ID: 48167
Summary: If "#pragma clang loop interleave_count(3)" is
specified for the loop, it is ignored.
Product: libraries
Version: trunk
Hardware: PC
OS: Linux
Status: NEW
Severity: enhancement
Priority: P
Component: Loop Optimizer
Assignee: unassignedbugs at nondot.org
Reporter: fj8765ah at aa.jp.fujitsu.com
CC: llvm-bugs at lists.llvm.org
"#pragma clang interleave_count(NUM)" appears to ignore NUM values that are not
powers of 2.
I think it is better to give priority to what is specified by pragma.
Does setting it to a value other than a power of 2 cause problems?
- interleave.c
void foo(double * restrict a,
double * restrict b,
double * restrict c,
int n) {
#ifdef PRAGMA
#pragma clang loop interleave_count(_NUM)
#endif
for (int i=0;i<n;i++)
c[i] = a[i] + b[i];
return;
}
If "#pragma clang interleave_count(3)" is specified, the interleave is 2.
$ clang -O3 interleave.c -Rpass=loop-vectorize -S
interleave.c:8:3: remark: vectorized loop (vectorization width: 2, interleaved
count: 2) [-Rpass=loop-vectorize]
for (int i=0;i<n;i++)
^
$ clang -O3 interleave.c -Rpass=loop-vectorize -S -DPRAGMA -D_NUM=1
interleave.c:8:3: remark: vectorized loop (vectorization width: 2, interleaved
count: 1) [-Rpass=loop-vectorize]
for (int i=0;i<n;i++)
^
$ clang -O3 interleave.c -Rpass=loop-vectorize -S -DPRAGMA -D_NUM=2
interleave.c:8:3: remark: vectorized loop (vectorization width: 2, interleaved
count: 2) [-Rpass=loop-vectorize]
for (int i=0;i<n;i++)
^
$ clang -O3 interleave.c -Rpass=loop-vectorize -S -DPRAGMA -D_NUM=3
interleave.c:8:3: remark: vectorized loop (vectorization width: 2, interleaved
count: 2) [-Rpass=loop-vectorize]
for (int i=0;i<n;i++)
^
I think it is set in the following part of the
"llvm/lib/Transforms/Vectorize/LoopVectorizationLegality.cpp" file.
If the value is not a power of 2, the if statement on line 235 is false and
ignored.
59 bool LoopVectorizeHints::Hint::validate(unsigned Val) {
60 switch (Kind) {
61 case HK_WIDTH:
62 return isPowerOf2_32(Val) && Val <=
VectorizerParams::MaxVectorWidth;
63 case HK_UNROLL:
64 return isPowerOf2_32(Val) && Val <= MaxInterleaveFactor;
65 case HK_FORCE:
66 return (Val <= 1);
67 case HK_ISVECTORIZED:
68 case HK_PREDICATE:
69 return (Val == 0 || Val == 1);
70 }
71 return false;
72 }
...
223 void LoopVectorizeHints::setHint(StringRef Name, Metadata *Arg) {
224 if (!Name.startswith(Prefix()))
225 return;
226 Name = Name.substr(Prefix().size(), StringRef::npos);
227
228 const ConstantInt *C = mdconst::dyn_extract<ConstantInt>(Arg);
229 if (!C)
230 return;
231 unsigned Val = C->getZExtValue();
232
233 Hint *Hints[] = {&Width, &Interleave, &Force, &IsVectorized,
&Predicate};
234 for (auto H : Hints) {
235 if (Name == H->Name) {
236 if (H->validate(Val))
237 H->Value = Val;
238 else
239 LLVM_DEBUG(dbgs() << "LV: ignoring invalid hint '" << Name <<
"'\n");
240 break;
241 }
242 }
243 }
--
You are receiving this mail because:
You are on the CC list for the bug.
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.llvm.org/pipermail/llvm-bugs/attachments/20201113/6d7df1df/attachment.html>
More information about the llvm-bugs
mailing list