CSU-CS-Melange / alpha-language

Forked from Inria gitlab
MIT License
0 stars 0 forks source link

Normalize bug - binExpr(op, caseExpr, caseExpr) #55

Closed lnarmour closed 5 months ago

lnarmour commented 5 months ago

Normalize incorrectly handles binary expressions involving two case expressions.

For example, take this program:

affine test11 [N] -> {  : N >= 6 }
    outputs
        Y : {[i]: 0 <= i <= N }
    when {  : N >= 6 } let
        Y[i] = (case  {
            {: i = 0 } : 0[];
            {: 0 < i < N } : 12[];
            {: i = N } : 1[];
        } + case  {
            {: i <= -4 + N } : 5[];
            {: i >= -3 + N } : 3[];
        });
.

This should produce the following 4 distinct values in Y:

  Y[0] =  0 + 5  -->   5
  Y[1] = 12 + 5  -->  17
  Y[2] = 12 + 5  -->  17
  Y[3] = 12 + 5  -->  17
   ...
Y[N-5] = 12 + 5  -->  17
Y[N-4] = 12 + 5  -->  17
Y[N-3] = 12 + 3  -->  15
Y[N-2] = 12 + 3  -->  15
Y[N-1] = 12 + 3  -->  15
  Y[N] =  1 + 3  -->   4

But if you run Normalize, it results in this program:

affine test11 [N] -> {  : N >= 6 }
    outputs
        Y : {[i]: 0 <= i <= N }
    when {  : N >= 6 } let
        Y[i] = case  {
            {: i = 0 } : (0[] + 0[]);
            {: 0 < i < N } : (12[] + 12[]);
            {: i = N } : (1[] + 1[]);
        };
.

The transformed program has 3 branches when there should be 4, and only the values for the left caseExpr appear after normalization. It looks like Normalize is losing the reference to the right caseExpr somehow. This may be related to issue #44, since the progam mentioned there also involves binExprs with multiple caseExprs.

ryanjob42 commented 5 months ago

Closed by PR #56