encyclopegia.org

Strength reduction

In compiler construction, strength reduction is a compiler optimization where expensive operations are replaced with equivalent but less expensive operations.[src] The classic example of strength reduction converts strong multiplications inside a loop into weaker additions – something that frequently occurs in array addressing.[src] Examples of strength reduction include replacing a multiplication within a loop with an addition and replacing exponentiation within a loop with a multiplication.[src]

In compiler construction, strength reduction is a compiler optimization where expensive operations are replaced with equivalent but less expensive operations.[src] The classic example of strength reduction converts strong multiplications inside a loop into weaker additions – something that frequently occurs in array addressing.[src] Examples of strength reduction include replacing a multiplication within a loop with an addition and replacing exponentiation within a loop with a multiplication.[src] c = 7; for (i = 0; i can be replaced with successive weaker additions c = 7; k = 0; for (i = 0; i for (i = 0; i ===Intermediate code=== The compiler will view this code as 0010 ; for (i = 0, i This expresses 2-dimensional array A as a 1-dimensional array of n*n size, so that whenever the high-level code expresses A[x, y] it will internally be A[(x*n)+y] for any given valid indices x and y.[src] 0010 ; for (i = 0, i There are more optimizations to do.[src] Register r3 is the main variable in the innermost loop (0140-0260); it gets incremented by 1 each time through the loop.[src] Register r8 (which is invariant in the innermost loop) is added to r3.[src] Instead of using r3, the compiler can eliminate r3 and use r9.[src] The loop, instead of being controlled by r3 = 0 to n-1, can be controlled by r9=r8+0 to r8+n-1.[src] That adds four instructions and kills four instructions, but there's one fewer instruction inside the loop.[src] 0110 ; r3 = #0 killed ; j = 0 0115 r9 = r8 ; new assignment 0117 r20 = r8 + r2 ; new limit 0120 G0002: 0140 ; cmp r3, r2 killed ; j Now r9 is the loop variable, but it interacts with the multiply by 8.[src] Here we get to do some strength reduction.[src] The multiply by 8 can be reduced to some successive additions of 8.[src] Now there are no multiplications inside the loop.[src] 0115 r9 = r8 ; new assignment 0117 r20 = r8 + r2 ; new limit 0118 r10 = r8 * #8 ; initial value of r10 0120 G0002: 0145 cmp r9, r20 ; r8 + j Registers r9 and r10 (= 8*r9) aren't both needed; r9 can be eliminated in the loop.[src] The loop is now 5 instructions.[src] 0115 ; r9 = r8 killed 0117 r20 = r8 + r2 ; limit 0118 r10 = r8 * #8 ; initial value of r10 0119 r22 = r20 * #8 ; new limit 0120 G0002: 0145 ; cmp r9, r20 killed ; r8 + j 0010 ; for (i = 0, i There are now four multiplications within the outer loop that increments r1.[src] Register r8 = r1*r2 at 0190 can be strength reduced by setting it before entering the loop (0055) and incrementing it by r2 at the bottom of the loop (0385).[src] The value r8*8 (at 0118) can be strength reduced by initializing it (0056) and adding 8*r2 to it when r8 gets incremented (0386).[src] Register r20 is being incremented by the invariant/constant r2 each time through the loop at 0117.[src] After being incremented, it is multiplied by 8 to create r22 at 0119.[src] That multiplication can be strength reduced by adding 8*r2 each time through the loop.[src] 0010 ; for (i = 0, i ===The last multiply=== That leaves the two loops with only one multiplication operation (at 0330) within the outer loop and no multiplications within the inner loop.[src] 0010 ; for (i = 0, i At line 0320, r14 is the sum of r8 and r1, and r8 and r1 are being incremented in the loop.[src] Register r8 is being bumped by r2 (=n) and r1 is being bumped by 1.[src] Consequently, r14 is being bumped by n+1 each time through the loop.[src] The last loop multiply at 0330 can be strength reduced by adding (r2+1)*8 each time through the loop.[src] 0010 ; for (i = 0, i There's still more to go.[src] Constant folding will recognize that r1=0 in the preamble, so several instructions will clean up.[src] Register r8 isn't used in the loop, so it can disappear.[src] Furthermore, r1 is only being used to control the loop, so r1 can be replaced by a different induction variable such as r40.[src] Where i went 0 0010 ; for (i = 0, i f x = ...[src] (3 ** x) ...[src] (f (x + 1)) ...[src] becomes f x = f' x 1 where f' x z = ...[src] z ...[src] (f' (x + 1) (3 * z)) ...[src] Here modified recursive function takes a second parameter z = 3 ** x, allowing the expensive computation (3 ** x) to be replaced by the cheaper (3 * z).[src] ==See also== Fast inverse square root Hacker's Delight Partial evaluation ==Notes== ==References==[src]

42 sentences · 42 cited inline · 0 references stored

References

No reference rows published for this article.

Cite this article

MLA

"Strength reduction." encyclopegia.org, 2026, https://encyclopegia.org/wiki/strength-reduction. Accessed 28 November 2026.

Chicago

"Strength reduction." encyclopegia.org. Accessed November 28, 2026. https://encyclopegia.org/wiki/strength-reduction.

APA

encyclopegia.org. (2026). Strength reduction. Retrieved November 28, 2026, from https://encyclopegia.org/wiki/strength-reduction

Accessed November 28, 2026 · CC BY-SA 4.0 · citation page · JSON

Related articles

Izod impact strength test

stub · references available

Strength athletics in Sweden

stub · references available

reduction

stub · references available

International Day for Disaster Reduction

stub · references available

reduction

stub · references available

received signal strength indication

stub · references available

That Hideous Strength

stub · references available

The Strength/The Sound/The Songs

stub · references available
CC BY-SA 4.0 · share-alike · https://en.wikipedia.org/w/index.php?oldid=1374353515 · 0.5 · snapshot enwiki-001374353515

Cite · JSON · Search

Related services and records

Services

  • Estate — measured countries, lanes and facts
  • Intel — live corroborated events
  • Legal — statutes, cases and citations
  • Encyclopedia — articles with inline sources
  • Space — launches, satellites and orbits
  • Search — federated search and reports
  • Pass — passport account and SSO
  • Corpora — read-only corpus origins
  • e01 — self-hosted corpora and tools
  • Careers — open roles: frontier engineers and sales partners

Text and metadata only; each target carries its own sources. Missing data is published as no-data, never estimated.