[llvm-commits] [PATCH] Fix SciMark2-C test case hanging
Simon Atanasyan
satanasyan at mips.com
Thu Oct 11 06:30:45 PDT 2012
Hi Duncan,
On Thu, Oct 11, 2012 at 9:50 AM, Duncan Sands <baldrick at free.fr> wrote:
>> Test case MultiSource\Benchmarks\SciMark2-C hangs [1] due excessive
>> optimization of SparseCompRow_matmult() routine. This function
>> computes a matrix-vector multiply with a sparse matrix. The result
>> vector is not used and optimizer throws away the function's body.
>
> how could this cause a hang?
Reduced test case is attached to this e-mail. Here is a command
reproduces the problem:
$ clang -O3 check.c
In short, original and reduced test cases contains the following code.
It repeats some calculations more and more and stops when execution
time exceeds a limit. The calculation result is stored in the array
but is not used anywhere. That is why the optimizer throws away the
array allocation/deallocation and the calculation and the loop runs
infinitely.
[[
int *arr = malloc(arrSize * sizeof(*arr));
int iterCount = 1;
clock_t start, delta;
while (1)
{
start = clock();
worker(iterCount, arr, arrSize); // do calculation "iterCount"
times and save result to "arr"
delta = clock() - start;
if (delta > CLOCKS_PER_SEC)
break;
iterCount *= 2;
}
free(arr);
]]
Here is a piece of LLVM assembly language corresponds to the "while loop":
[[
while.body.us.i: ; preds =
%while.body.us.i, %entry
%call1.us.i = tail call i32 @clock() nounwind
%call2.us.i = tail call i32 @clock() nounwind
%sub.us.i = sub nsw i32 %call2.us.i, %call1.us.i
%cmp.us.i = icmp sgt i32 %sub.us.i, 1000000
br i1 %cmp.us.i, label %run.exit, label %while.body.us.i
run.exit: ; preds = %while.body.us.i
ret i32 0
]]
>> The attached patch does a trick to prevent optimization and fixes this
>> problem.
>
> Are you saying that the optimization is wrong? If so it is the optimizers
> that should be fixed...
There was a discussion about similar optimization in this thread:
http://goo.gl/QIHBC. As far as I understand the optimization is
correct in general. But in the SciMark2-C test case we measure a
calculation speed and compare results with gcc. The optimization does
not allow to do that and we have to escape it.
My patch does that in a tricky way. Maybe more clear and excplicit
approach is to use the calculation result somehow. For example, sum
all array's elements and print. That do you think?
--
Regards,
Simon
-------------- next part --------------
A non-text attachment was scrubbed...
Name: check.c
Type: text/x-csrc
Size: 646 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/llvm-commits/attachments/20121011/6ce42fbc/attachment.c>
More information about the llvm-commits
mailing list