EMRL bug
The following example:
use Array: all;
use StdIO: all;
#define N 20
#define BS 10
noinline
float[N] stencil_1D_fix (float[3] weights, int n, float[N] v)
{
for (i=0; i<n; i++) {
v = { iv -> sum (weights * tile ([3], iv-1, v)) | [1] <= iv < [N-1];
iv -> v[iv] };
}
return v;
}
int main()
{
a = genarray( [N], 0f);
a[10] = 10f;
print (a);
b = stencil_1D_fix ([0.25f,0.5f,0.25f], 10, a);
print (b);
print (a);
return 0;
}
when compiled with
sac2c 1.3.3-MijasCosta-1032-gff7ec
build-type: RELEASE
built-by: "sbs" at 2023-01-16T16:50:26
using no flags, yields the erroneous result:
-sbs-n142121-> ./a.out
Dimension: 1
Shape : < 20>
<0.000000 0.000000 0.000000 0.000000 0.000000 0.000000 0.000000 0.000000 0.000000 0.000000 10.000000 0.000000 0.000000 0.000000 0.000000 0.000000 0.000000 0.000000 0.000000 0.000000 >
Dimension: 1
Shape : < 20>
<0.000000 0.000191 0.001812 0.010872 0.046206 0.147858 0.369644 0.739288 1.201344 1.601791 1.761971 1.601791 1.201344 0.739288 0.369644 0.147858 0.046206 0.010872 0.001802 0.000000 >
Dimension: 1
Shape : < 20>
<0.000000 0.000191 0.001812 0.010872 0.046206 0.147858 0.369644 0.739288 1.201344 1.601791 1.761971 1.601791 1.201344 0.739288 0.369644 0.147858 0.046206 0.010872 0.001802 0.000000 >
When compiled with -noEMRL
, we get the correct result:
-sbs-n142121-> ./a.out
Dimension: 1
Shape : < 20>
<0.000000 0.000000 0.000000 0.000000 0.000000 0.000000 0.000000 0.000000 0.000000 0.000000 10.000000 0.000000 0.000000 0.000000 0.000000 0.000000 0.000000 0.000000 0.000000 0.000000 >
Dimension: 1
Shape : < 20>
<0.000000 0.000191 0.001812 0.010872 0.046206 0.147858 0.369644 0.739288 1.201344 1.601791 1.761971 1.601791 1.201344 0.739288 0.369644 0.147858 0.046206 0.010872 0.001802 0.000000 >
Dimension: 1
Shape : < 20>
<0.000000 0.000000 0.000000 0.000000 0.000000 0.000000 0.000000 0.000000 0.000000 0.000000 10.000000 0.000000 0.000000 0.000000 0.000000 0.000000 0.000000 0.000000 0.000000 0.000000 >