Skip to content

Conversation

@afonso360
Copy link
Contributor

When encoding constants as immediates into an RSE Imm12 instruction we need to take special care to check if the value that we are trying to input does not overflow its type when viewed as a signed value. (i.e. iconst.i8 200)

We cannot both put an immediate and sign extend it, so we need to lower it into a separate reg, and emit the sign extend into the instruction.

For more details see the cg_clif bug report.

@github-actions github-actions bot added cranelift Issues related to the Cranelift code generator cranelift:area:aarch64 Issues related to AArch64 backend. labels Jul 3, 2021
@afonso360 afonso360 force-pushed the aarch64-fix-overflow-imm branch from 0c2bad1 to 236c3c1 Compare July 3, 2021 12:48
Copy link
Member

@cfallin cfallin left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks for finding the issue!

I am thinking that it may be better to reconsider whether "large const values" (actually "values that overflow their type") should be allowed at all; that would solve this in a nicer way, IMHO.

@cfallin
Copy link
Member

cfallin commented Jul 3, 2021

Ah, actually, nevermind the above; we don't have signedness at the CLIF type level (I need more coffee this morning) so this is a valid input and it's just an encoding issue.

Copy link
Member

@cfallin cfallin left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

OK, sorry about my misunderstanding above: this looks good!

Happy to merge with the mentioned simplification of the is_negative logic.

@afonso360 afonso360 force-pushed the aarch64-fix-overflow-imm branch from 236c3c1 to a5cc0b8 Compare July 3, 2021 20:25
When encoding constants as immediates into an RSE Imm12 instruction we need to take special care to check if the value that we are trying to input does not overflow its type when viewed as a signed value. (i.e. iconst.i8 200)

We cannot both put an immediate and sign extend it, so we need to lower it into a separate reg, and emit the sign extend into the instruction.

For more details see the [cg_clif bug report](https://github.com/bjorn3/rustc_codegen_cranelift/issues/1184#issuecomment-873214796).
@afonso360 afonso360 force-pushed the aarch64-fix-overflow-imm branch from a5cc0b8 to eebae8d Compare July 3, 2021 21:42
@cfallin cfallin merged commit c71ad94 into bytecodealliance:main Jul 3, 2021
@afonso360 afonso360 deleted the aarch64-fix-overflow-imm branch September 2, 2021 13:26
uweigand added a commit to uweigand/wasmtime that referenced this pull request Sep 11, 2021
- Add relocation handling needed after PR bytecodealliance#3275
- Fix incorrect handling of signed constants detected by PR bytecodealliance#3056 test
- Disable fuzzing tests that require pre-built v8 binaries
- Disable cranelift test that depends on i128
- Temporarily disable memory64 tests
@uweigand uweigand mentioned this pull request Sep 11, 2021
uweigand added a commit to uweigand/wasmtime that referenced this pull request Sep 13, 2021
- Add relocation handling needed after PR bytecodealliance#3275
- Fix incorrect handling of signed constants detected by PR bytecodealliance#3056 test
- Fix LabelUse max pos/neg ranges; fix overflow in buffers.rs
- Disable fuzzing tests that require pre-built v8 binaries
- Disable cranelift test that depends on i128
- Temporarily disable memory64 tests
alexcrichton pushed a commit that referenced this pull request Sep 20, 2021
- Add relocation handling needed after PR #3275
- Fix incorrect handling of signed constants detected by PR #3056 test
- Fix LabelUse max pos/neg ranges; fix overflow in buffers.rs
- Disable fuzzing tests that require pre-built v8 binaries
- Disable cranelift test that depends on i128
- Temporarily disable memory64 tests
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

cranelift:area:aarch64 Issues related to AArch64 backend. cranelift Issues related to the Cranelift code generator

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants