Search Results for '컴파일러 최적화'

2 POSTS

  1. 2006.09.18 Algebraic Simplification
  2. 2006.09.18 Strength Reduction

Algebraic Simplification

Posted 2006. 9. 18. 01:49
algebraic simpification은 직관적인 컴파일러 최적화 기법이다. 예를 들어, 더하기 연산자(+ operator)의 항등원이 0 이라는 사실을 이용해 x + 0 이라는 expression을 x로 치환하는 것을 말한다.

원래 코드

main(int x, int y)
{
x = (y*1 + 0)/1;
}

변환 후에는

main(int x, int y)
{
x = y;
}

Strength Reduction

Posted 2006. 9. 18. 01:19
strength reduction은 타겟 머신에서 무거운(expensive) 연산을 가벼운(cheap) 연산으로 바꾸는 컴파일러 최적화 기법을 말한다. 쉬운 예로, 곱하기 연산을 더하기 연산으로 바꾸는 경우를 들 수 있다.

썬 마이크로시스템즈에서 나온 다음 논문(
Operator Strength Reduction)에 자세한 설명이 있다.

Operator strength reduction is a technique that improves compiler-generated code by reformulating
certain costly computations in terms of less expensive ones. A common case arises in array
addressing expressions used in loops. The compiler can replace the sequence of multiplies generated
by a direct translation of the address expression with an equivalent sequence of additions.


구체적인 예로는

for i from 1 to n do
   z= i*x
  ...
end

위와 같은 코드를 다음과 같이 바꿔 주는 것이다.

z=0;
for i from 1 to n do
  z=z+x
  ..
end