Bug 1610053 - SystemZ combines away AND masks that are necessary for i128 shifts
Summary: SystemZ combines away AND masks that are necessary for i128 shifts
Keywords:
Status: CLOSED ERRATA
Alias: None
Product: DevTools
Classification: Red Hat
Component: llvm
Version: llvm-toolset-7
Hardware: s390x
OS: Unspecified
unspecified
unspecified
Target Milestone: rc
: 2018.4
Assignee: Tom Stellard
QA Contact: Miloš Prchlík
URL:
Whiteboard:
Depends On:
Blocks: 1562186 1562192 1591301 1611608
TreeView+ depends on / blocked
 
Reported: 2018-07-30 23:31 UTC by Josh Stone
Modified: 2018-11-13 15:20 UTC (History)
5 users (show)

Fixed In Version: llvm-toolset-6.0-llvm-6.0.1-3.el7
Doc Type: No Doc Update
Doc Text:
undefined
Clone Of:
Environment:
Last Closed: 2018-11-13 15:19:35 UTC
Target Upstream Version:
Embargoed:


Attachments (Terms of Use)


Links
System ID Private Priority Status Summary Last Updated
Red Hat Product Errata RHBA-2018:3583 0 None None None 2018-11-13 15:20:15 UTC

Description Josh Stone 2018-07-30 23:31:15 UTC
I reduced Rust bug 1562192 to this:

    #![feature(test)]

    extern crate test;

    #[inline(never)]
    fn foo(f: f32) -> i128 {
        let sign_bit = 1u32 << 31;
        let significand_bits = 23;
        let exponent_bias = 127;

        let a_abs = f.to_bits() & !sign_bit;
        let exponent = (a_abs >> significand_bits) - exponent_bias;
        1i128 << (exponent - significand_bits)
    }

    fn main() {
        let f = test::black_box(0x8000_00 as f32);
        println!("{:x}", foo(f));
    }

Compile it optimized with: env RUSTC_BOOTSTRAP=1 rustc -O [file.rs]

On s390x, this produces the following IR:

    ; i128::foo
    ; Function Attrs: noinline norecurse nounwind readnone uwtable
    define internal fastcc i128 @_ZN4i1283foo17h5b7dd13bfb54356eE(float %f) unnamed_addr #2 {
    start:
      %0 = bitcast float %f to i32
      %1 = lshr i32 %0, 23
      %2 = add nuw nsw i32 %1, 106
      %3 = and i32 %2, 127
      %4 = zext i32 %3 to i128
      %5 = shl i128 1, %4
      ret i128 %5
    }

Note the "add 106" instead of subtracting exponent_bias and significand_bits, but the "and 127" is supposed to mask that back into range.

SystemZTargetLowering::combineSHIFTROT deems that AND useless and removes it.  That might be ok for native instructions, but "shl i128" calls __ashlti3, which does require the value to be in range.

I have a patch review here: <https://reviews.llvm.org/D50018>, but the first comment says SHL poison makes that transform was wrong even for smaller integers.

Comment 1 Tom Stellard 2018-08-07 04:44:24 UTC
Fixed in llvm-toolset-6.0-llvm-6.0.1-3.el7.

Comment 3 Miloš Prchlík 2018-10-01 12:49:53 UTC
Verified with build llvm-toolset-6.0-llvm-6.0.1-5.el7.

Comment 5 errata-xmlrpc 2018-11-13 15:19:35 UTC
Since the problem described in this bug report should be
resolved in a recent advisory, it has been closed with a
resolution of ERRATA.

For information on the advisory, and where to find the updated
files, follow the link below.

If the solution does not work for you, open a new bug report.

https://access.redhat.com/errata/RHBA-2018:3583


Note You need to log in before you can comment on or make changes to this bug.