[project @ 2005-10-31 11:17:53 by simonmar]
authorsimonmar <unknown>
Mon, 31 Oct 2005 11:17:53 +0000 (11:17 +0000)
committersimonmar <unknown>
Mon, 31 Oct 2005 11:17:53 +0000 (11:17 +0000)
x86_64: catch and fix one kind of crappy code generated by gcc

    #    movq -4(%rbp), %rax
    #    jmp  *%rax

==>

    #    jmp  *-4(%rbp)

ghc/driver/mangler/ghc-asm.lprl

index 8a66422..63b753f 100644 (file)
@@ -1430,12 +1430,24 @@ sub hppa_mash_prologue { # OK, epilogue, too
 sub print_doctored {
     local($_, $need_fallthru_patch) = @_;
 
+    if ( $TargetPlatform =~ /^x86_64-/ ) {
+           # Catch things like
+           #   
+           #    movq -4(%ebp), %rax
+           #    jmp  *%rax
+           # 
+           # and optimise:
+           #
+           s/^\tmovq\s+(-?\d*\(\%r(bx|bp)\)),\s*(\%r(ax|cx|dx|10|11))\n\tjmp\s+\*\3/\tjmp\t\*$1/g;
+    }
+
     if ( $TargetPlatform !~ /^i386-/ 
       || ! /^\t[a-z]/  # no instructions in here, apparently
       || /^${T_US}__stginit_[A-Za-z0-9_]+${T_POST_LBL}/) {
        print OUTASM $_;
        return;
     }
+
     # OK, must do some x86 **HACKING**
 
     local($entry_patch)        = '';