#15104 closed bug (fixed)

Update JMP_TBL targets during shortcutting for x86 codegen.

Reported by: AndreasK Owned by:
Priority: normal Milestone: 8.6.1
Component: Compiler (NCG) Version: 8.5
Keywords: CodeGen Cc:
Operating System: Unknown/Multiple Architecture: Unknown/Multiple
Type of failure: None/Unknown Test Case:
Blocked By: Blocking:
Related Tickets: Differential Rev(s): Phab:D4595
Wiki Page:


Jump tables are generated from Cmm Code in a few steps:

  1. We start with a CmmSwitch at the end of the Cmm pipeline which gets turned into a JMP_TBL instruction.
  2. During native codegen we generate static jump tables from JMP_TBL. (generateJumpTables)
  3. We shortcut jump targets, for jump tables by updating the static tables. (shortcutBranches). This might update the jump targets with calculated address not represented by a label.

After the third step the targets in the JMP_TBL instruction (which are the original labels) and in the static data can be out of sync.

Phab:D4566 went part of the way, updating labels in JMP_TBL. However without tables next to code labels can be updated to non-label jump destinations which I did not consider at the time.

Phab:D4595 is intended to fix this.

Change History (3)

comment:1 Changed 17 months ago by AndreasK

Status: newpatch

comment:2 Changed 16 months ago by Ben Gamari <ben@…>

In 5748c79e/ghc:

Change jump targets in JMP_TBL from blocks to X86.JumpDest.

Jump tables always point to blocks when we first generate them.  However
there are rare situations where we can shortcut one of these blocks to a
static address during the asm shortcutting pass.

While we already updated the data section accordingly this patch also
extends this to the references stored in JMP_TBL.

Test Plan: ci

Reviewers: bgamari

Reviewed By: bgamari

Subscribers: thomie, carter

GHC Trac Issues: #15104

Differential Revision: https://phabricator.haskell.org/D4595

comment:3 Changed 16 months ago by bgamari

Resolution: fixed
Status: patchclosed
Note: See TracTickets for help on using tickets.