Legalize unsigned-to-float conversions for Intel 64.
Also make sure we generate type checks for the controlling type variable in legalization patterns. This is not needed for encodings since the encoding tables are already keyed on the controlling type variable.
This commit is contained in:
@@ -7,7 +7,7 @@ for patern matching an rewriting of cretonne instructions.
|
||||
from __future__ import absolute_import
|
||||
from . import instructions
|
||||
from .typevar import TypeVar
|
||||
from .predicates import IsEqual, And, TypePredicate
|
||||
from .predicates import IsEqual, And, TypePredicate, CtrlTypePredicate
|
||||
|
||||
try:
|
||||
from typing import Union, Tuple, Sequence, TYPE_CHECKING, Dict, List # noqa
|
||||
@@ -383,12 +383,38 @@ class Apply(Expr):
|
||||
|
||||
pred = And.combine(pred, IsEqual(ffield, arg))
|
||||
|
||||
# Add checks for any bound type variables.
|
||||
for bound_ty, tv in zip(self.typevars, self.inst.all_typevars()):
|
||||
if bound_ty is None:
|
||||
continue
|
||||
type_chk = TypePredicate.typevar_check(self.inst, tv, bound_ty)
|
||||
pred = And.combine(pred, type_chk)
|
||||
# Add checks for any bound secondary type variables.
|
||||
# We can't check the controlling type variable this way since it may
|
||||
# not appear as the type of an operand.
|
||||
if len(self.typevars) > 1:
|
||||
for bound_ty, tv in zip(self.typevars[1:],
|
||||
self.inst.other_typevars):
|
||||
if bound_ty is None:
|
||||
continue
|
||||
type_chk = TypePredicate.typevar_check(self.inst, tv, bound_ty)
|
||||
pred = And.combine(pred, type_chk)
|
||||
|
||||
return pred
|
||||
|
||||
def inst_predicate_with_ctrl_typevar(self):
|
||||
# type: () -> PredNode
|
||||
"""
|
||||
Same as `inst_predicate()`, but also check the controlling type
|
||||
variable.
|
||||
"""
|
||||
pred = self.inst_predicate()
|
||||
|
||||
if len(self.typevars) > 0:
|
||||
bound_ty = self.typevars[0]
|
||||
type_chk = None # type: PredNode
|
||||
if bound_ty is not None:
|
||||
# Prefer to look at the types of input operands.
|
||||
if self.inst.use_typevar_operand:
|
||||
type_chk = TypePredicate.typevar_check(
|
||||
self.inst, self.inst.ctrl_typevar, bound_ty)
|
||||
else:
|
||||
type_chk = CtrlTypePredicate(bound_ty)
|
||||
pred = And.combine(pred, type_chk)
|
||||
|
||||
return pred
|
||||
|
||||
|
||||
@@ -35,7 +35,8 @@ try:
|
||||
from .typevar import TypeVar # noqa
|
||||
PredContext = Union[SettingGroup, InstructionFormat,
|
||||
InstructionContext]
|
||||
PredLeaf = Union[BoolSetting, 'FieldPredicate', 'TypePredicate']
|
||||
PredLeaf = Union[BoolSetting, 'FieldPredicate', 'TypePredicate',
|
||||
'CtrlTypePredicate']
|
||||
PredNode = Union[PredLeaf, 'Predicate']
|
||||
# A predicate key is a (recursive) tuple of primitive types that
|
||||
# uniquely describes a predicate. It is used for interning.
|
||||
@@ -373,3 +374,42 @@ class TypePredicate(object):
|
||||
"""
|
||||
return 'dfg.value_type(args[{}]) == {}'.format(
|
||||
self.value_arg, self.value_type.rust_name())
|
||||
|
||||
|
||||
class CtrlTypePredicate(object):
|
||||
"""
|
||||
An instruction predicate that checks the controlling type variable
|
||||
|
||||
:param value_type: The required value type.
|
||||
"""
|
||||
|
||||
def __init__(self, value_type):
|
||||
# type: (ValueType) -> None
|
||||
assert value_type is not None
|
||||
self.value_type = value_type
|
||||
|
||||
def __str__(self):
|
||||
# type: () -> str
|
||||
return 'ctrl_typevar:{}'.format(self.value_type)
|
||||
|
||||
def predicate_context(self):
|
||||
# type: () -> PredContext
|
||||
return instruction_context
|
||||
|
||||
def predicate_key(self):
|
||||
# type: () -> PredKey
|
||||
return ('ctrltypecheck', self.value_type.name)
|
||||
|
||||
def predicate_leafs(self, leafs):
|
||||
# type: (Set[PredLeaf]) -> None
|
||||
leafs.add(self)
|
||||
|
||||
def rust_predicate(self, prec):
|
||||
# type: (int) -> str
|
||||
"""
|
||||
Return Rust code for evaluating this predicate.
|
||||
|
||||
It is assumed that the context has `dfg` and `inst` variables.
|
||||
"""
|
||||
return 'dfg.ctrl_typevar(inst) == {}'.format(
|
||||
self.value_type.rust_name())
|
||||
|
||||
@@ -199,7 +199,7 @@ def unwrap_inst(iref, node, fmt):
|
||||
n = expr.inst.value_opnums.index(opnum)
|
||||
fmt.format('dfg.resolve_aliases(args[{}]),', n)
|
||||
# Evaluate the instruction predicate, if any.
|
||||
instp = expr.inst_predicate()
|
||||
instp = expr.inst_predicate_with_ctrl_typevar()
|
||||
fmt.line(instp.rust_predicate(0) if instp else 'true')
|
||||
fmt.outdented_line('} else {')
|
||||
fmt.line('unreachable!("bad instruction format")')
|
||||
|
||||
@@ -96,3 +96,6 @@ for cc, rev_cc in [
|
||||
# We need to modify the CFG for min/max legalization.
|
||||
intel_expand.custom_legalize(insts.fmin, 'expand_minmax')
|
||||
intel_expand.custom_legalize(insts.fmax, 'expand_minmax')
|
||||
|
||||
# Conversions from unsigned need special handling.
|
||||
intel_expand.custom_legalize(insts.fcvt_from_uint, 'expand_fcvt_from_uint')
|
||||
|
||||
Reference in New Issue
Block a user