Add expansion patterns for large immediates.

Expand foo_imm into iconst + foo.
This commit is contained in:
Jakob Stoklund Olesen
2016-11-07 13:05:37 -08:00
parent a7c58b817c
commit d76280afba
2 changed files with 21 additions and 2 deletions

View File

@@ -19,3 +19,14 @@ ebb0(v1: i32, v2: i32):
; It's possible the legalizer will rewrite these value aliases in the future. ; It's possible the legalizer will rewrite these value aliases in the future.
; check: $v4 -> $cout ; check: $v4 -> $cout
; check: return $v3, $v4 ; check: return $v3, $v4
; Expanding illegal immediate constants.
; Note that at some point we'll probably expand the iconst as well.
function large_imm(i32) -> i32 {
ebb0(v0: i32):
v1 = iadd_imm v0, 1000000000
return v1
}
; check: $(cst=$V) = iconst.i32 0x3b9a_ca00
; check: $v1 = iadd $v0, $cst
; check: return $v1

View File

@@ -7,10 +7,10 @@ patterns that describe how base instructions can be transformed to other base
instructions that are legal. instructions that are legal.
""" """
from __future__ import absolute_import from __future__ import absolute_import
from .instructions import iadd, iadd_cout, iadd_cin, iadd_carry from .instructions import iadd, iadd_cout, iadd_cin, iadd_carry, iadd_imm
from .instructions import isub, isub_bin, isub_bout, isub_borrow from .instructions import isub, isub_bin, isub_bout, isub_borrow
from .instructions import band, bor, bxor, isplit_lohi, iconcat_lohi from .instructions import band, bor, bxor, isplit_lohi, iconcat_lohi
from .instructions import icmp from .instructions import icmp, iconst
from cdsl.ast import Var from cdsl.ast import Var
from cdsl.xform import Rtl, XFormGroup from cdsl.xform import Rtl, XFormGroup
@@ -127,3 +127,11 @@ expand.legalize(
(a, b2) << isub_bout(a1, b_in), (a, b2) << isub_bout(a1, b_in),
b << bor(b1, b2) b << bor(b1, b2)
)) ))
# Expansions for immediates that are too large.
expand.legalize(
a << iadd_imm(x, y),
Rtl(
a1 << iconst(y),
a << iadd(x, a1)
))