Open gnzlbg opened 6 years ago
A few questions and annotations.
0 >> 1
1 >> 0
work?2 >> 1
work?is the order of the parameter correct [...] I can't find the doc to simd_shr
simd_shr
is an undocumented compiler intrinsic for internal use in the std library only (not exposed to users), so it isn't really documented anywhere. Its type checked here, and it's lowered to LLVM IR here, by generating a ashr (here), with the arguments of simd_shr
passed in order to ashr
.
The LLVM's LangRef documents ashr
as:
The ‘ashr’ instruction (arithmetic shift right) returns the first operand shifted to the right a specified number of bits with sign extension.
That is, the first argument of ashr is the value to be shifted, and the second value is the number of bits to shift.
So it appears that the argument order is correct. The LLVM IR Builder for ashr also appears ok (here).
Why don't you write 0i128.
This was produced from minimizing code that uses as
and was failing only on s390x
on debug builds, so I just kept that in the MWE.
I've just tried to use 0_i128
instead and that does not reproduce the issue, so maybe this has something to do with EDIT: I am dumb and disabled the test while trying out this change, using as
? cc @eddyb0_i128
does still reproduce the issue. The latest commit in the repo has this.
Does this only affect 1xi128 vectors or does it reproduce with a scalar i128 too?
Does this only affect 1xi128 vectors or does it reproduce with a scalar i128 too?
I've added the equivalent test using i128
to the repo (see below) and it does not panic, so it appears to only affect vectors. In stdsimd
I can reproduce this with i128x1
and i128x2
only (and shr only IIRC, shl appears to work correctly), all other tests for s390x-unknown-linux-gnu pass successfully.
This test passes (it does not panic):
#[test]
pub fn scalar_test() {
let z = 0_i128;
let o = 1_i128;
if o >> z != o {
panic!();
}
}
This test also fails for sparc64-unknown-linux-gnu
Now that godbolt supports cross-compilation for rust, it is much easier to try to debug this (https://godbolt.org/g/No8zpS):
example::scalar_test:
stmg %r14, %r15, 112(%r15)
aghi %r15, -160
j .LBB47_1
.LBB47_1:
lhi %r0, 1
chi %r0, 0
jlh .LBB47_3
j .LBB47_2
.LBB47_2:
larl %r2, .Lbyte_str.6
larl %r4, .Lbyte_str.5
lghi %r3, 14
brasl %r14, std::panicking::begin_panic@PLT
.Ltmp29:
j .Ltmp29+2
.LBB47_3:
lmg %r14, %r15, 272(%r15)
br %r14
.Lbyte_str.4:
.ascii "/tmp/compiler-explorer-compiler118710-63-1i2e6ad.i6ghg/example.rs"
.Lbyte_str.5:
.quad .Lbyte_str.4
.ascii "\000\000\000\000\000\000\000A\000\000\000\007\000\000\000\t"
.Lbyte_str.6:
.ascii "explicit panic"
from
define void @_ZN7example11scalar_test17h9448becacb3cda6dE() unnamed_addr #0 {
br label %bb1
bb1: ; preds = %start
br i1 false, label %bb2, label %bb3
bb2: ; preds = %bb1
call void @_ZN3std9panicking11begin_panic17h0260f1c8a33dd8a1E([0 x i8]* noalias nonnull readonly bitcast (<{ [14 x i8] }>* @byte_str.6 to [0 x i8]*), i64 14, { [0 x i64], { [0 x i8]*, i64 }, [0 x i32], i32, [0 x i32], i32, [0 x i32] }* noalias readonly dereferenceable(24) bitcast (<{ i8*, [16 x i8] }>* @byte_str.5 to { [0 x i64], { [0 x i8]*, i64 }, [0 x i32], i32, [0 x i32], i32, [0 x i32] }*))
unreachable
bb3: ; preds = %bb1
ret void
}
so everything looks correct now, I am restarting the build but travis is having issues. If the build still fails I don't know what's the problem here.
What happened on Travis?
I've restarted the build: https://travis-ci.org/gnzlbg/repro_s390x/builds/399684908
It still fails.
I cannot reproduce it on a s390x machine anymore so I think it is fixed
[linux1@rusting repro_s390x]$ cargo +nightly test
Compiling repro_s390x v0.1.0 (/home/linux1/dev/rustbug/repro_s390x)
Finished test [unoptimized + debuginfo] target(s) in 2.09s
Running unittests (target/debug/deps/repro_s390x-8197d3a364efe000)
running 2 tests
test scalar_test ... ok
test vector_test ... ok
Tested on a vm provided by Marist College through the community cloud https://linuxone.cloud.marist.edu/
I've set up a repository that reproduces this issue on travis (using qemu): https://github.com/gnzlbg/repro_s390x
The following code right shifts a
<1 x i128>
containing1
by0
. The result of the shift should be1
, but on debug builds it is0
, causing the following code to panic (on release the code does not panic):The
test
function generates the following LLVM-IRwhich is lowered to
cc @rkruppe
Who maintains Rust's SystemZ support?