Branch: Tag:

2015-04-26

2015-04-26 12:38:33 by Henrik Grubbström (Grubba) <grubba@grubba.org>

Peep: Propagate constants past assignments.

This makes several peep hole rules redundant.

Also removes a few dead and/or redundant rules.

Fixes [CID 1294690].

59:   CONST_1 ADD_INTS COMPL : NEGATE   ADD_NEG_INT(1) COMPL : NEGATE   CONST1 SUBTRACT COMPL : NEGATE - NUMBER ASSIGN_LOCAL NEGATE: NUMBER($1a) ASSIGN_LOCAL_AND_POP($2a) NEG_NUMBER($1a) - NEG_NUMBER ASSIGN_LOCAL NEGATE: NEG_NUMBER($1a) ASSIGN_LOCAL_AND_POP($2a) NUMBER($1a) - CONST1 ASSIGN_LOCAL NEGATE: CONST1 ASSIGN_LOCAL_AND_POP($2a) CONST_1 - CONST_1 ASSIGN_LOCAL NEGATE: CONST_1 ASSIGN_LOCAL_AND_POP($2a) CONST1 +     - CONST0 ASSIGN_LOCAL: CLEAR_LOCAL($2a) CONST0 -  +    LOCAL_2_LOCAL [$1a == $1b] :   GLOBAL ASSIGN_GLOBAL_AND_POP($1a) :   
98:   LOCAL_LVALUE LTOSVAL ADD_NEG_INT [ !INT32_NEG_OVERFLOW($3a) ] ASSIGN: ADD_LOCAL_INT($1a,-$3a)      NUMBER ASSIGN_LOCAL_AND_POP : ASSIGN_LOCAL_NUMBER_AND_POP($2a,$1a) + NEG_NUMBER ASSIGN_LOCAL_AND_POP [ !INT32_NEG_OVERFLOW($1a) ] : ASSIGN_LOCAL_NUMBER_AND_POP($2a,-$1a)   CONST0 ASSIGN_LOCAL_AND_POP : CLEAR_LOCAL($2a)   CONST1 ASSIGN_LOCAL_AND_POP : ASSIGN_LOCAL_NUMBER_AND_POP($2a,1)   CONST_1 ASSIGN_LOCAL_AND_POP : ASSIGN_LOCAL_NUMBER_AND_POP($2a,-1)      NUMBER ASSIGN_GLOBAL_AND_POP : ASSIGN_GLOBAL_NUMBER_AND_POP($2a,$1a) -  + NEG_NUMBER ASSIGN_GLOBAL_AND_POP [ !INT32_NEG_OVERFLOW($1a) ] : ASSIGN_GLOBAL_NUMBER_AND_POP($2a,-$1a)   CONST0 ASSIGN_GLOBAL_AND_POP : ASSIGN_GLOBAL_NUMBER_AND_POP($2a,0)   CONST1 ASSIGN_GLOBAL_AND_POP : ASSIGN_GLOBAL_NUMBER_AND_POP($2a,1)   CONST_1 ASSIGN_GLOBAL_AND_POP : ASSIGN_GLOBAL_NUMBER_AND_POP($2a,-1)    -  + // Propagate constants past assignments. + NUMBER ASSIGN_LOCAL : ASSIGN_LOCAL_NUMBER_AND_POP($2a,$1a) NUMBER($1a) + NEG_NUMBER ASSIGN_LOCAL [ !INT32_NEG_OVERFLOW($1a) ] : ASSIGN_LOCAL_NUMBER_AND_POP($2a,-$1a) NEG_NUMBER($1a) + CONST0 ASSIGN_LOCAL : CLEAR_LOCAL($2a) CONST0 + CONST1 ASSIGN_LOCAL : ASSIGN_LOCAL_NUMBER_AND_POP($2a,1) CONST1 + CONST_1 ASSIGN_LOCAL : ASSIGN_LOCAL_NUMBER_AND_POP($2a,-1) CONST_1 +  + NUMBER ASSIGN_GLOBAL : ASSIGN_GLOBAL_NUMBER_AND_POP($2a,$1a) NUMBER($1a) + NEG_NUMBER ASSIGN_GLOBAL [ !INT32_NEG_OVERFLOW($1a) ] : ASSIGN_GLOBAL_NUMBER_AND_POP($2a,-$1a) NEG_NUMBER($1a) + CONST0 ASSIGN_GLOBAL : ASSIGN_GLOBAL_NUMBER_AND_POP($2a,0) CONST0 + CONST1 ASSIGN_GLOBAL : ASSIGN_GLOBAL_NUMBER_AND_POP($2a,1) CONST1 + CONST_1 ASSIGN_GLOBAL : ASSIGN_GLOBAL_NUMBER_AND_POP($2a,-1) CONST_1 +    // Remove clearing of locals from the beginning of functions   // But don't remove clearing of arguments!   BYTE ENTRY START_FUNCTION LABEL(0) CLEAR_LOCAL [$1a <= $5a] : BYTE($1a) ENTRY START_FUNCTION LABEL(0)
354:      // This set of optimizations is broken. Consider the case:   // STRING ADD_INT ADD_INT + //   // ADD_INT ADD_INT: ADD_INTS ($1a+$2a)   // ADD_NEG_INT ADD_NEG_INT: ADD_NEG_INT ($1a+$2a)   // ADD_NEG_INT ADD_INT [$1a <= $2a]: ADD_INT ($2a-$1a)
779:   MARK ASSIGN_GLOBAL_NUMBER_AND_POP: ASSIGN_GLOBAL_NUMBER_AND_POP($2a,$2b) MARK   MARK NEG_NUMBER ASSIGN_LOCAL_AND_POP: NEG_NUMBER($2a) ASSIGN_LOCAL_AND_POP($3a) MARK   MARK NEG_NUMBER ASSIGN_GLOBAL_AND_POP: NEG_NUMBER($2a) ASSIGN_GLOBAL_AND_POP($3a) MARK - MARK_AND_CONST1 ASSIGN_LOCAL_AND_POP: CONST1 ASSIGN_LOCAL_AND_POP($3a) MARK - MARK_AND_CONST1 ASSIGN_GLOBAL_AND_POP: CONST1 ASSIGN_GLOBAL_AND_POP($3a) MARK - MARK CONST_1 ASSIGN_GLOBAL_AND_POP: CONST_1 ASSIGN_GLOBAL_AND_POP($3a) MARK -  - CONST_1 ASSIGN_LOCAL COMPL : CONST_1 ASSIGN_LOCAL_AND_POP($2a) CONST0 - CONST_1 ASSIGN_GLOBAL COMPL : CONST_1 ASSIGN_GLOBAL_AND_POP($2a) CONST0 -  - CONST0 ASSIGN_LOCAL COMPL : CLEAR_LOCAL($2a) CONST_1 - CONST0 ASSIGN_GLOBAL COMPL : CONST0 ASSIGN_GLOBAL_AND_POP($2a) CONST_1 + MARK_AND_CONST1 ASSIGN_LOCAL_AND_POP: ASSIGN_LOCAL_NUMBER_AND_POP($3a,1) MARK + MARK_AND_CONST1 ASSIGN_GLOBAL_AND_POP: ASSIGN_GLOBAL_NUMBER_AND_POP($3a,1) MARK