libminizinc icon indicating copy to clipboard operation
libminizinc copied to clipboard

Common Subexpression Elimination

Open a1880 opened this issue 7 years ago • 1 comments

I am working on a problem with lots of re-occuring common subexpressions. Inspecting the FlatZinc intermediate file, I noticed that the subexpressions are not eliminated. Therefore, I tried to use a let construct to nudge the compiler in CSE direction:

%  F[], G[] and D[] are arrays of var bool 
constraint
	forall(i in ARows, j in ACols, m in BRows, n in BCols) (
        let {
          array[Products] of var bool: dyad = [F[i,j,k] /\ G[m,n,k] | k in Products];
        } in
        forall(p in CRows, q in CCols) (
	    if ((i != p) \/ (j != m) \/ (n != q)) then
	        iffall([(dyad[k] /\ D[p, q, k]) | k in Products])
	    else
	        xorall([(dyad[k] /\ D[p, q, k]) | k in Products])
	    endif
        )
	);

This did not help. The FlatZinc code contains all 3-input conjunctions and the compiler replaced my construct by the same result it would create from:

constraint
	forall(i in ARows, j in ACols, m in BRows, n in BCols, p in CRows, q in CCols) (
	    if ((i != p) \/ (j != m) \/ (n != q)) then
	        iffall([(F[i, j, k] /\ G[m, n, k] /\ D[p, q, k]) | k in Products])
	    else
	        xorall([(F[i, j, k] /\ G[m, n, k] /\ D[p, q, k]) | k in Products])
	    endif
	);

Is there a way to achieve common subexpression for my example? Or does it make no sense to attempt this anyhow?

a1880 avatar Sep 22 '17 12:09 a1880

That's AC-CSE on conjunction.

pwn1 avatar Feb 02 '18 14:02 pwn1