Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add sextOrBitCast to conversions of Builtin.Word #19600

Merged
merged 1 commit into from Oct 1, 2018
Merged

Add sextOrBitCast to conversions of Builtin.Word #19600

merged 1 commit into from Oct 1, 2018

Commits on Sep 28, 2018

  1. Add sextOrBitCast to conversions of Builtin.Word

    An error was hit when attempting to build Swift on a 32-bit Linux host. It was asserting when attempting to run ‘RedunantLoadElim” during the optimizer. The reason why is a bit messy.
    
    First, Builtin.Word is always considered to be 64-bit when it is a SILType. This means the optimizer, when working with a Builtin.Word, will create 64-bit APInts when converting from other types.
    
    Second, the SIL being output for a particular literal looked like this:
    Int2048 (integer_literal) : Int32 (Signed Truncation) : Word (zextOrBitCast)
    
    The constant fold behavior would convert this into an integer_literal of the Builtin.Word type. But because of the zext cast, if the original literal was -1, it would become +4 billion during folding.
    
    This normally isn’t a problem **except** when SIL is still attempting to optimize. (See First)
    
    Third, The Redundant Load Elimination pass was attempting to make sense of an index_addr instruction which was indexing at -1. This happens when you perform “-= 1” on an UnsafePointer. Because SIL was interpreting Word’s size incorrectly, it caused the RLE pass to ask “what is the ProjectionKind at ptr[4billion]?” Since there’s no feasible answer for such a question, the answer was “nothing” when the Projection’s kind() was checked, which tripped the assert.
    
    This fix uses sign extension when converting “upward” and the Integer type is signed, otherwise it will still use zero extension.
    Kaiede committed Sep 28, 2018
    Configuration menu
    Copy the full SHA
    7288f26 View commit details
    Browse the repository at this point in the history