Skip to content

Strength reduction for add operations performed power of 2 times #34938

@kunalspathak

Description

@kunalspathak
static uint i4(uint i) {
	return i + i + i + i;
}

Above code should obviously be return 4 * i, but today if we see something like this, we don't optimize it that way and perform add operations. We could optimize it to lsl if adds are performed in power of 2.
Today we generate:

G_M48040_IG02:
        0B000001          add     w1, w0, w0
        0B000021          add     w1, w1, w0
        0B000020          add     w0, w1, w0

We should generate:

        531E7400          lsl     w0, w0, #2

We never optimize even for 8 or 16 operations and thus emitting series of add operations.

category:cq
theme:basic-cq
skill-level:intermediate
cost:medium

Metadata

Metadata

Assignees

Labels

area-CodeGen-coreclrCLR JIT compiler in src/coreclr/src/jit and related components such as SuperPMIoptimization

Type

No type

Projects

No projects

Relationships

None yet

Development

No branches or pull requests

Issue actions