Page MenuHomePhabricator

InstCombine: Narrow switch instruction operands using known bits
ClosedPublic

Authored by ahatanak on Oct 8 2014, 6:35 PM.

Details

Reviewers
pete
majnemer
Summary

This patch adds an inst-combine optimization which narrows the operands of a switch instruction if the upper bits are known to be all 1 or 0.

For example, since the upper 32-bits are all zero in the following switch instruction,

%and = and i64 %a, 4294967295
switch i64 %and, label %sw.default [

i64 10, label %return
i64 100, label %sw.bb1
i64 1001, label %sw.bb2

]

we can turn it into a 32-bit instruction:

switch i32 %and, label %sw.default [

i32 10, label %return
i32 100, label %sw.bb1
i32 1001, label %sw.bb2

]

Diff Detail

Event Timeline

ahatanak updated this revision to Diff 14610.Oct 8 2014, 6:35 PM
ahatanak retitled this revision from to InstCombine: Narrow switch instruction operands using known bits.
ahatanak updated this object.
ahatanak edited the test plan for this revision. (Show Details)
ahatanak added a subscriber: Unknown Object (MLST).

I'd recommend to add @majnemer as reviewer.

pete accepted this revision.Oct 15 2014, 11:35 AM
pete added a reviewer: pete.
pete added a subscriber: pete.

I think it makes sense to truncate down to the largest legal type as you've done here. Anything lower than that gets tricky to reason about the quality of code in the backends.

LGTM.

This revision is now accepted and ready to land.Oct 15 2014, 11:35 AM

Thanks Pete. Committed r219832.