Skip to content

address constants forced to registers in small-model static-reloc x86-64 #1434

@sunfishcode

Description

@sunfishcode
Bugzilla Link 1062
Resolution FIXED
Resolved on Feb 22, 2010 12:55
Version 1.9
OS Linux

Extended Description

Weak, extern and linkonce symbols are currently excluded from address
operands in x86-64 with the small memory model and static linking.

With this test case:

%x = external global int

implementation

int %foo(long %i) {
%a = getelementptr int* %x, long %i
%t = load int* %a
ret int %t
}

Currently llc -march=x86-64 -code-model=small -relocation-model=static
emits this:

    leaq x(%rip), %rcx
    movl (%rcx,%rax,4), %eax

I believe should emit this:

    movl x(,%rax,4), %eax

Unless I'm missing something, it should be safe to let llc do this,
with the following patch.

Index: X86ISelDAGToDAG.cpp

RCS file: /var/cvs/llvm/llvm/lib/Target/X86/X86ISelDAGToDAG.cpp,v
retrieving revision 1.138
diff -u -r1.138 X86ISelDAGToDAG.cpp
--- X86ISelDAGToDAG.cpp
+++ X86ISelDAGToDAG.cpp
@@ -604,9 +604,7 @@
SDOperand N0 = N.getOperand(0);
if (GlobalAddressSDNode *G = dyn_cast(N0)) {
GlobalValue *GV = G->getGlobal();

  •    bool isAbs32 = !is64Bit ||
    
  •      (isStatic && !(GV->isExternal() || GV->hasWeakLinkage() ||
    
  •                     GV->hasLinkOnceLinkage()));
    
  •    bool isAbs32 = !is64Bit || isStatic;
       if (isAbs32 || isRoot) {
         AM.GV = G->getGlobal();
         AM.Disp += G->getOffset();
    

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions