afonso360 opened PR #7047 from afonso360:riscv-dedup-trap
to bytecodealliance:main
:
:wave: Hey,
This PR cleans up our trap instructions in the backend. We have 2 "TrapIf" style instructions. One that compares against zero, and a second that does any integer comparison. This PR does a couple of changes.
Merge both
TrapIf
andTrapIfC
. The newTrapIf
instruction allows trapping with any integer condition. This is the first commit, and it does not change any of the emitted instruction sequences, just our printing.Use the new
MachBuffer::defer_trap
(#6011) method to place trap opcodes out of line. This does actually change the golden tests, and is contained to the second commit.Lastly, the
defer_trap
change exposed a bug in our lowering ofbr_table
. Previously we were emitting islands right before the jump table targets, but crucially after calculating the jump offset. This meant that if the island were actually emitted, we could jump right into the middle of it!This was exposed by the
defer_trap
change since the test case would emit a trap before a hugebr_table
, forcing the island, and then jump into offset 0, which actually ended up being the trap opcode instead of the branch target.We now emit the island at the start of the
br_table
sequence instead of in the middle.
afonso360 requested wasmtime-compiler-reviewers for a review on PR #7047.
afonso360 requested fitzgen for a review on PR #7047.
afonso360 edited PR #7047:
:wave: Hey,
This PR cleans up our trap instructions in the backend. We have 2 "TrapIf" style instructions. One that compares against zero, and a second that does any integer comparison. This PR does a couple of changes.
Merge both
TrapIf
andTrapIfC
. The newTrapIf
instruction allows trapping with any integer condition. This is the first commit, and it does not change any of the emitted instruction sequences, just our printing.Use the new
MachBuffer::defer_trap
(#6011) method to place trap opcodes out of line. This does actually change the golden tests, and is contained to the second commit.Lastly, the
defer_trap
change exposed a bug in our lowering ofbr_table
. Previously we were emitting islands right before the jump table targets, but crucially after calculating the jump offset. This meant that if the island were actually emitted, we could jump right into the middle of it!This was exposed by the
defer_trap
change since the test case would emit a trap before a hugebr_table
, forcing the island, and then jump into the firstbr_table
target, which actually ended up being the trap opcode instead of the branch target.We now emit the island at the start of the
br_table
sequence instead of in the middle.
afonso360 edited PR #7047:
:wave: Hey,
This PR cleans up our trap instructions in the backend. We have 2 "TrapIf" style instructions. One that compares against zero, and a second that does any integer comparison. This PR does a couple of changes.
Merge both
TrapIf
andTrapIfC
. The newTrapIf
instruction allows trapping with any integer condition. This is the first commit, and it does not change any of the emitted instruction sequences, just our printing.Use the new
MachBuffer::defer_trap
(#6011) method to place trap opcodes out of line. This does actually change the golden tests, and is contained to the second commit.Lastly, the
defer_trap
change exposed a bug in our lowering ofbr_table
. Previously we were emitting islands right before the jump table targets, but crucially after calculating the jump offset. This meant that if the island were actually emitted, we could jump right into the middle of it!This was exposed by the
defer_trap
change since the test case would emit a trap before a hugebr_table
, forcing the island, and then jump into the firstbr_table
target, which actually ended up being the trap opcode instead of the intended branch target.We now emit the island at the start of the
br_table
sequence instead of in the middle.
alexcrichton submitted PR review.
alexcrichton submitted PR review.
alexcrichton created PR review comment:
This is confusing me a bit as
trapif
seems to trap if the condition succeeds, so the condition here is that if the input is not equal to zero this is trapping, asserting the register is zero. The function, however, is intended to trap if the register is zero.Should the helper perhaps be
trapnz
?
alexcrichton created PR review comment:
Along the lines of the above, should this perhaps become a
trapz
helper?
afonso360 updated PR #7047.
afonso360 submitted PR review.
afonso360 created PR review comment:
Yeah, looks like I got a bit confused here. Thanks for catching this!
afonso360 updated PR #7047.
afonso360 updated PR #7047.
alexcrichton merged PR #7047.
Last updated: Dec 23 2024 at 13:07 UTC