test-memrt-lift1 problems
These are most likely two bugs in one.
test-memrt-lift1.sac fails in the current cuda-mappings-branch. Closer inspection shows that the develop version exposes some weird code as well.
The original test code is:
use Array: all;
inline
int[+] onestep (int[+] B)
{
A = with {
(. < x < .) : 2 * (B[x+[1,0]]
+ B[x-[1,0]]
+ B[x+[0,1]]
+ B[x-[0,1]]);
} : modarray (B);
return(A);
}
noinline
int[+] operation (int[+] A)
{
steps = 100;
do {
B = A;
A = onestep (B);
steps--;
} while ((sum (A) > sum (B)) && (steps > 0));
return (A);
}
int main ()
{
A = with {
([0,1] <= x <= .) : 0;
} : genarray ([1000,1000], 500);
A = operation (A);
return _toi_S_ (A[100,100]);
}
The develop version ( 1.3.3-MijasCosta-672-g1ad640) generates for operation:
int[1000,1000] _MAIN::operation( int[1000,1000] A { ,NN } )
/*
* operation :: ---
*/
{
int_dev[1000,1000] _iwlmem_3481_dev { , NN } ;
int{0} _dlirmov_3445__pinl_840__flat_3 { , NN } ;
int[1000,1000] A__SSA0_1 { , NN } ; /* declared: int[+] */
int{100} steps { , NN } ;
int[1000,1000] _emrl_3478_emr_lifted { , NN } ; /* declared: int[1000,1000] */
steps = 100;
_dlirmov_3445__pinl_840__flat_3 = 0;
/** Is allowed to be moved up **/
_iwlmem_3481_dev = /* ERC () */ _host2device_( _emrl_3478_emr_lifted);
A__SSA0_1 = _MAIN::_dup_64_operation__Loop_1( _dlirmov_3445__pinl_840__flat_3, steps, A, _iwlmem_3481_dev) ;
return( A__SSA0_1);
}
ie it transfers an unitialised _emrl_3478_emr_lifted to the device which then correctly acts as ERC. However, the transfer is not making any sense here.
To make matters worse, the current cuda-mappings branch for some reason does not lift the transfer out of the loop at all; doing an illegal transfer inside the loop:
int[1000,1000] _MAIN::_dup_64_operation__Loop_1( int{0} _pinl_840__flat_3 { ,NN } , int steps { ,NN } , int[1000,1000] A { ,NN } , int[1000,1000] _emrl_3497_emr_tmp { ,NN } )
// elided decls
/** Is NOT allowed to be moved up **/
_iwlmem_3501_dev = /* ERC () */ _host2device_( _emrl_3497_emr_tmp);
/** Is NOT allowed to be moved up **/
_iwlmem_3500_dev = /* ERC () */ _host2device_( A);
where this function is initially called with
int[1000,1000] _MAIN::operation( int[1000,1000] A { ,NN } )
/*
* operation :: ---
*/
{
int{0} _dlirmov_3465__pinl_840__flat_3 { , NN } ;
int[1000,1000] A__SSA0_1 { , NN } ; /* declared: int[+] */
int{100} steps { , NN } ;
int[1000,1000] _emrl_3498_emr_lifted { , NN } ; /* declared: int[1000,1000] */
steps = 100;
_dlirmov_3465__pinl_840__flat_3 = 0;
A__SSA0_1 = _MAIN::_dup_64_operation__Loop_1( _dlirmov_3465__pinl_840__flat_3, steps, A, _emrl_3498_emr_lifted) ;
ie, _emrl_3498_emr_lifted is passed without being initialised.....