This is an archive of the discontinued LLVM Phabricator instance.

[mips][FastISel] Apply only zero-extension to constants prior to their materialization.
ClosedPublic

Authored by vkalintiris on Jul 29 2015, 6:52 AM.

Details

Summary

Previously, we would sign-extend non-boolean negative constants and
zero-extend otherwise. This was problematic for PHI instructions with
negative values that had a type with bitwidth less than that of the
register used for materialization.

More specifically, ComputePHILiveOutRegInfo() zero-extends (or
truncates to the bitwidth of destination-type) the constants present
in a PHI node, and afterwards deduces the known bits.

For example, previously we would materialize an i16 -4 with the
following instruction:

addiu $r, $zero, -4

The register would end-up with the 32-bit 2's complement representation
of -4. However, ComputePHILiveOutRegInfo() would generate a constant
with the upper 16-bits set to zero. The SelectionDAG builder would use
that information to generate an AzzertZero node that would remove any
subsequent trunc & zero_extend nodes.

In theory, we should modify ComputePHILiveOutRegInfo() to consult
target-specific hooks about the way they prefer to materialize the
given constants. However, git-blame reports that this specific code
has not been touched since 2011 and it seems to be working well for every
target so far.

Diff Detail

Repository
rL LLVM

Event Timeline

vkalintiris retitled this revision from to [mips][FastISel] Apply only zero-extension to constants prior to their materialization..
vkalintiris updated this object.
vkalintiris added a reviewer: dsanders.
vkalintiris added a subscriber: llvm-commits.
dsanders accepted this revision.Jul 30 2015, 4:18 AM
dsanders edited edge metadata.

LGTM. I agree that the real issue is that the analysis of known bits is getting the excess bits wrong and we ought to fix that but this patch at least fixes the known issues in Mips's Fast ISel. We can follow up on the known-bits analysis afterwards.

More specifically, ComputePHILiveOutRegInfo() zero-extends (or
truncates to the bitwidth of destination-type) ...

These aren't quite the same thing. Is it assuming values are zero extended in their container or is considering the excess bits to be undefined? From your later comments I'm sure it's the former.

AzzertZero

Nit: Typo

This revision is now accepted and ready to land.Jul 30 2015, 4:18 AM
This revision was automatically updated to reflect the committed changes.