Only create copy_nop instructions for types for which an encoding exists. Issue #779.
PR #773 detects, at reload time, `copy` instructions that copy a value from stack slot back to the same stack slot. It replaces them with `copy_nop` instructions that have a null encoding (hence producing no code). For x86_64, `copy_nop` encodings for the types I64, I32, F64 and F32 are provided. Unfortunately the code that detects the redundant copy doesn't check the type of the copied value, hence leaving itself open to the danger of creating a `copy_nop` instruction cannot be encoded (which is different from saying it has a null encoding). This patch: * Expands the x86_64 set of `copy_nop` encodings to: I64 I32 I16 I8 F64 and F32 * Adds encodings for the same for x86_32, rv64 and rv32. * In `visit_inst()` in `reload.rs`, checks the type of the copied value accordingly. * Adds comments explaining the above.
This commit is contained in:
@@ -3,12 +3,13 @@ RISC-V Encodings.
|
||||
"""
|
||||
from __future__ import absolute_import
|
||||
from base import instructions as base
|
||||
from base import types
|
||||
from base.immediates import intcc
|
||||
from .defs import RV32, RV64
|
||||
from .recipes import OPIMM, OPIMM32, OP, OP32, LUI, BRANCH, JALR, JAL
|
||||
from .recipes import LOAD, STORE
|
||||
from .recipes import R, Rshamt, Ricmp, Ii, Iz, Iicmp, Iret, Icall, Icopy
|
||||
from .recipes import U, UJ, UJcall, SB, SBzero, GPsp, GPfi, Irmov
|
||||
from .recipes import U, UJ, UJcall, SB, SBzero, GPsp, GPfi, Irmov, stacknull
|
||||
from .settings import use_m
|
||||
from cdsl.ast import Var
|
||||
from base.legalize import narrow, expand
|
||||
@@ -160,3 +161,9 @@ RV32.enc(base.copy.b1, Icopy, OPIMM(0b000))
|
||||
RV64.enc(base.copy.b1, Icopy, OPIMM(0b000))
|
||||
RV32.enc(base.regmove.b1, Irmov, OPIMM(0b000))
|
||||
RV64.enc(base.regmove.b1, Irmov, OPIMM(0b000))
|
||||
|
||||
# Stack-slot-to-the-same-stack-slot copy, which is guaranteed to turn
|
||||
# into a no-op.
|
||||
for ty in [types.i64, types.i32, types.i16, types.i8, types.f64, types.f32]:
|
||||
RV64.enc(base.copy_nop.bind(ty), stacknull, 0)
|
||||
RV32.enc(base.copy_nop.bind(ty), stacknull, 0)
|
||||
|
||||
@@ -223,3 +223,8 @@ GPfi = EncRecipe(
|
||||
'GPfi', Unary, base_size=4,
|
||||
ins=Stack(GPR), outs=GPR,
|
||||
emit='unimplemented!();')
|
||||
|
||||
# Stack-slot-to-the-same-stack-slot copy, which is guaranteed to turn
|
||||
# into a no-op.
|
||||
stacknull = EncRecipe('stacknull', Unary, base_size=0,
|
||||
ins=Stack(GPR), outs=Stack(GPR), emit='')
|
||||
|
||||
Reference in New Issue
Block a user