Competition Rules

In gimple tree, there are some opportunities to decrease the executed statements by combining several into one. The following rules are for preventing these feasible but illegal optimizations.

  • Left hand side of an assignment statement should be a variable or an array access.
  • Right hand side of an assignment statement should be either a variable, a constant, an array access, a function call or an expression with no more than two operands (or one operator).
  • If there is an array access in an assignment statement, the statement has only two operands - one is the array access and the other is a variable.
  • Any operand of an expression can only be a variable or a constant.
  • The predicate of a conditional jump can be one comparison operation whose two operands are either a variable or a constant.
  • Parameters to a function call can only be a variable or a constant.
  • Index of an array can only be a variable or a constant.
  • Return parameter can only be a variable or a constant.

NOTICE: Actually, you do NOT need to do any work to make the gimple tree to follow the above rules because gcc has already simplified it.

After the program transformation, new temporary variables could be introduced. An example program segment

    a = b + c[e] + d;
    if (a+d<b) goto L1;
         foo (m[a+d]);
         m[e+f] = m[a] + m[d];

needs to be converted to something like the following:

  t1 = c[e];
  t2 = t1 + b;
  a = t2 + d;
  t3 = a + d;
  if (t3 < b) goto L1;

  t4 = a + d;
  t5 = m[t4];
  foo (t5);
  t6 = e + f;
  t7 = m[a];
  t8 = m[d];
  t9 = t7 + t8;
  m[t6] = t9;


You should take scanf and printf as special instructions that need not conform to above specifications. You should not make any temporary variable to take value of the pointer passed to scanf. Remember that our language does not have pointers, so we do not deal with them. For printf, you still need to make all the arguments in variable or constant form except for the format string.

-- XiaomingGu - 08 Apr 2008

Edit | Attach | Watch | Print version | History: r2 < r1 | Backlinks | Raw View | Raw edit | More topic actions...
Topic revision: r1 - 2008-04-08 - XiaomingGu
  • Edit
  • Attach
This site is powered by the TWiki collaboration platform Powered by PerlCopyright © 2008-2017 by the contributing authors. All material on this collaboration platform is the property of the contributing authors.
Ideas, requests, problems regarding URCS? Send feedback