
What Kind of Optimization Is Being Performed?
3-19
Optimizing Your Code
Example 3
−
3. Data-Flow Optimizations
simp(int j)
{
int a = 3;
int b = (j * a) + (j * 2);
int c = (j << a);
int d = (j >> 3) + (j << b);
call(a,b,c,d);
...
}
TMS320C2x/C2xx/C5x C Compiler Output:
_simp:
. . .
*****************************************************
* b = j * 5;
*****************************************************
LARK
AR2,−3+LF1
; AR2 = &j
MAR
*0+
LT
*
; t = *AR2
MPYK
5
; p = t * 5
ADRK
4−LF1
; AR2 = &b
SPL
*
; *AR2 = p
*****************************************************
* call(3, b, j << 3, (j >> 3) + (j << b));
*****************************************************
LT
*
; t = *AR2 (b)
SBRK
4−LF1
; AR2 = &j
LACT
* ,AR1
; ACC = j << b
SACL
* ,AR2
; save off ACC on TOS (top of stack)
SSXM
; need sign extension for right shift
LAC
* ,12,AR1
; high ACC = j >> 3
ADD
* ,15
; add TOS to high ACC
SACH
*+,1,AR2
; stack high ACC
LAC
* ,3,AR1
; ACC = j << 3
SACL
*+,AR2
; stack ACC
ADRK
4−LF1
; AR2 = &b
LAC
* ,AR1
; ACC = b
SACL
*+
; stack ACC
CALLD
_call
; call begins
LACK
3
; ACC = 3
SACL
*+
; stack ACC
***
CALL
_call OCCURS
; call occurs
. . .
The constant 3, assigned to a, is copy propagated to all uses of a; a becomes a dead variable
and is eliminated. The sum of multiplying j by 3 (a) and 2 is simplified into b = j * 5, which is recog-
nized as a common subexpression. The assignments to c and d are dead and are replaced with
their expressions. These optimizations are performed across jumps.
Содержание TMS320C2x
Страница 8: ...viii...
Страница 69: ...2 47 C Compiler Description...
Страница 159: ...6 36...
Страница 226: ...8 6...
Страница 250: ...Index Index 14 Z z shell option 2 2 2 4 2 14 overriding with c option 4 5 overriding with n option 2 13...