llvm / llvm-project

The LLVM Project is a collection of modular and reusable compiler and toolchain technologies.
http://llvm.org
Other
25.92k stars 10.57k forks source link

Invalid operand found in inline asm: 'movl %gs:${1:P},$0' #3751

Closed edwintorok closed 2 years ago

edwintorok commented 15 years ago
Bugzilla Link 3379
Resolution FIXED
Resolved on Apr 28, 2009 16:52
Version unspecified
OS Linux
Blocks llvm/llvm-bugzilla-archive#4064
CC @asl

Extended Description

Another one from the kernel

typedef unsigned long long u64; extern typeof(int) per_cpucpu_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_cpucpu_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, 36, %reg0, 1, %reg0,

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

llvmbot commented 2 years ago

mentioned in issue llvm/llvm-bugzilla-archive#4064

asl commented 15 years ago

This should fix it, I think:

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

edwintorok commented 15 years ago

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 ; [#uses=0] %1 = load i64 @​boot_pat_state, align 8 ; [#uses=1] %asmtmp = call i32 asm "movl %gs:${1:P},$0", "=r,m,~{dirflag},~{fpsr},~{flags}"(i32 @​per_cpu__cpu_number) nounwind ; [#uses=1] store i32 %asmtmp, i32* %ret %2 = load i32 %ret__, align 4 ; [#uses=1] store i32 %2, i32 %0, align 4 %3 = load i32 %0, align 4 ; [#uses=1] %4 = load i64 %pat, align 8 ; [#uses=1] %5 = call i32 (...) @​printk(i8 getelementptr ([50 x i8]* @.str, i32 0, i64 0), i32 %3, i64 %1, i64 %4) nounwind ; [#uses=0] br label %return

return: ; preds = %entry ret void }

declare i32 @​printk(...)

lattner commented 15 years ago

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.