Skip to content
This repository was archived by the owner on Jun 26, 2020. It is now read-only.

Legalize i64.const by breaking it into two i32.const#957

Merged
bnjbvr merged 2 commits intobytecodealliance:masterfrom
bnjbvr:iconst-i64
Sep 10, 2019
Merged

Legalize i64.const by breaking it into two i32.const#957
bnjbvr merged 2 commits intobytecodealliance:masterfrom
bnjbvr:iconst-i64

Conversation

@bnjbvr
Copy link
Member

@bnjbvr bnjbvr commented Aug 30, 2019

So my current thinking about isplit/iconcat is that both should not appear post-legalization, and every isplit must have an iconcat input, so the iconcat results are used instead. This seems to make sense if isplit/iconcat are just type system artifacts.

So trying a very simple program on x86 32-bits, that is generating an i64 constant, I implemented this legalization. This could be done in the meta language if there was literal support in the legalize patterns (cc @abrown).

Now it's funny because it interacts with f64const generation on 32 bits (so the test will fail, hence the WIP status of this PR). f64const are generated by reproducing the bit pattern in an i64, then bitcasting this to a f64 register. This is wrong on 32 bits platforms, where instead we should probably legalize it into two GPRs and then bitcast this to a f64. Or implement real constant pools for f32/f64, which would be even better.

@bjorn3
Copy link
Contributor

bjorn3 commented Aug 30, 2019

Or implement real constant pools for f32/f64, which would be even better.

LLVM does that for both f32 and f64.

black_box(0.1f64);
[...]
movsd	.LCPI10_0(%rip), %xmm0
callq	core::hint::black_box
[...]

@bnjbvr
Copy link
Member Author

bnjbvr commented Sep 6, 2019

Remaining to do: don't simplify operations into immediate operations if the ctrl value type is bigger than the native pointer type.

@bnjbvr bnjbvr marked this pull request as ready for review September 9, 2019 16:29
@bnjbvr bnjbvr removed the request for review from julian-seward1 September 10, 2019 16:56
…ry legalization;

Converting something like iadd.i64 on a 32-bits architecture into a
iadd_imm.i64 will result in the instruction being legalized back to an
iadd.i64 later on, creating unnecessary churn.

This commit implements avoid doing so, and changes the target ISA to a
64-bits platform for tests than ran into this, as well as making sure
this won't happen on 32-bits platforms.
@bnjbvr bnjbvr merged commit 302bcf3 into bytecodealliance:master Sep 10, 2019
@bnjbvr bnjbvr deleted the iconst-i64 branch September 11, 2019 11:58
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants