LLVM Bugzilla is read-only and represents the historical archive of all LLVM issues filled before November 26, 2021. Use github to submit LLVM bugs

Bug 3379 - Invalid operand found in inline asm: 'movl %gs:${1:P},$0'
Summary: Invalid operand found in inline asm: 'movl %gs:${1:P},$0'
Status: RESOLVED FIXED
Alias: None
Product: new-bugs
Classification: Unclassified
Component: new bugs (show other bugs)
Version: unspecified
Hardware: PC Linux
: P normal
Assignee: Unassigned LLVM Bugs
URL:
Keywords:
Depends on:
Blocks: 4064
  Show dependency tree
 
Reported: 2009-01-23 16:01 PST by Török Edwin
Modified: 2009-04-28 16:52 PDT (History)
3 users (show)

See Also:
Fixed By Commit(s):


Attachments

Note You need to log in before you can comment on or make changes to this bug.
Description Török Edwin 2009-01-23 16:01:24 PST
Another one from the kernel

typedef unsigned long long u64;
    extern __typeof__(int) per_cpu__cpu_number;
    static u64 __attribute__((__section__(".data.read_mostly"))) boot_pat_state;
    void pat_init(void) {
    u64 pat;
    printk("<6>" "x86 PAT enabled: cpu %d, old 0x%Lx, new 0x%Lx\n",         (({
  typeof(per_cpu__cpu_number) ret__;
  switch (sizeof(per_cpu__cpu_number)) {
 case 4: asm("mov" "l ""%%""gs"":%P" "1"",%0" : "=r" (ret__) : "m" (per_cpu__cpu_number));
 }
  ret__;
  }
  )), boot_pat_state, pat);
   }

$ llvm-gcc testcase-min.i
Invalid operand found in inline asm: 'movl %gs:${1:P},$0'
  INLINEASM <es:movl %gs:${1:P},$0>, 10, %ECX<def>, 36, %reg0, 1, %reg0, <ga:per_cpu__cpu_number>

With %1 gcc generates this:
  movl %gs:per_cpu__cpu_number,%eax

Without %P gcc generates this:
  movl %gs:per_cpu__cpu_number(%rip),%eax
Comment 1 Chris Lattner 2009-01-23 16:34:53 PST
does this patch fix it (and produce the correct suffix)?
http://lists.cs.uiuc.edu/pipermail/llvm-commits/Week-of-Mon-20090119/072614.html

If not, please attach a .bc file produced with -emit-llvm, thanks.
Comment 2 Török Edwin 2009-01-24 03:16:29 PST
(In reply to comment #1)
> does this patch fix it (and produce the correct suffix)?
> http://lists.cs.uiuc.edu/pipermail/llvm-commits/Week-of-Mon-20090119/072614.html
> 
> If not, please attach a .bc file produced with -emit-llvm, thanks.
> 

I get an error from LLC now, bitcode below

llc: /home/edwin/llvm-bootstrap/llvm/include/llvm/Target/TargetRegisterInfo.h:255: static bool llvm::TargetRegisterInfo::isPhysicalRegister(unsigned int): Assertion `Reg && "this is not a register!"' failed.
0   llc       0x0000000000c6e29f
1   libc.so.6 0x00007f91fb3e0f60
2   libc.so.6 0x00007f91fb3e0ed5 gsignal + 53
3   libc.so.6 0x00007f91fb3e23f3 abort + 387
4   libc.so.6 0x00007f91fb3d9dc9 __assert_fail + 233
5   llc       0x000000000075df7f
6   llc       0x000000000075e91c
7   llc       0x0000000000a0bfaf llvm::AsmPrinter::printInlineAsm(llvm::MachineInstr const*) const + 1647
8   llc       0x000000000075eba1
9   llc       0x000000000075f884
10  llc       0x0000000000c09bfb llvm::FPPassManager::runOnFunction(llvm::Function&) + 347
11  llc       0x0000000000c09ff6 llvm::FunctionPassManagerImpl::run(llvm::Function&) + 134
12  llc       0x0000000000c0a17e llvm::FunctionPassManager::run(llvm::Function&) + 62
13  llc       0x00000000004fbbc1 main + 4193
14  libc.so.6 0x00007f91fb3cd1a6 __libc_start_main + 230
15  llc       0x00000000004fa0b9 std::ios_base::Init::~Init() + 57
Aborted


target datalayout = "e-p:64:64:64-i1:8:8-i8:8:8-i16:16:16-i32:32:32-i64:64:64-f32:32:32-f64:64:64-v64:64:64-v128:128:128-a0:0:64-s0:64:64-f80:128:128"
target triple = "x86_64-unknown-linux-gnu"
@boot_pat_state = internal global i64 0, section ".data.read_mostly"            ; <i64*> [#uses=1]
@per_cpu__cpu_number = external global i32              ; <i32*> [#uses=1]
@.str = internal constant [50 x i8] c"<6>x86 PAT enabled: cpu %d, old 0x%Lx, new 0x%Lx\0A\00"           ; <[50 x i8]*> [#uses=1]

define void @pat_init() nounwind {
entry:
        %ret__ = alloca i32             ; <i32*> [#uses=2]
        %pat = alloca i64               ; <i64*> [#uses=1]
        %0 = alloca i32         ; <i32*> [#uses=2]
        %"alloca point" = bitcast i32 0 to i32          ; <i32> [#uses=0]
        %1 = load i64* @boot_pat_state, align 8         ; <i64> [#uses=1]
        %asmtmp = call i32 asm "movl %gs:${1:P},$0", "=r,*m,~{dirflag},~{fpsr},~{flags}"(i32* @per_cpu__cpu_number) nounwind                ; <i32> [#uses=1]
        store i32 %asmtmp, i32* %ret__
        %2 = load i32* %ret__, align 4          ; <i32> [#uses=1]
        store i32 %2, i32* %0, align 4
        %3 = load i32* %0, align 4              ; <i32> [#uses=1]
        %4 = load i64* %pat, align 8            ; <i64> [#uses=1]
        %5 = call i32 (...)* @printk(i8* getelementptr ([50 x i8]* @.str, i32 0, i64 0), i32 %3, i64 %1, i64 %4) nounwind           ; <i32> [#uses=0]
        br label %return

return:         ; preds = %entry
        ret void
}

declare i32 @printk(...)
Comment 3 Anton Korobeynikov 2009-04-28 16:52:33 PDT
This should fix it, I think:

http://lists.cs.uiuc.edu/pipermail/llvm-commits/Week-of-Mon-20090427/076811.html