[PATCH] D144439: [X86] Disable base pointer register when it is clobbered.

LuoYuanke via Phabricator via llvm-commits llvm-commits at lists.llvm.org
Mon Feb 20 16:30:22 PST 2023


LuoYuanke created this revision.
Herald added subscribers: pengfei, hiraditya.
Herald added a project: All.
LuoYuanke requested review of this revision.
Herald added a project: LLVM.
Herald added a subscriber: llvm-commits.

The base pointer register is reserved by compiler when there is
dynamic size alloca and stack realign in a function. However the
base pointer register is not defined in X86 ABI, so user can use
this register in inline assembly. The inline assembly would
clobber base pointer register without being awared by user. This
patch to disable the base pointer register when compiler detect
it is clobbered. Below is the example code for such case.

extern int bar(void *p);
long long foo(size_t size, char c, int id) {

  __attribute__((__aligned__(64))) int a;
  char *p = (char *)alloca(size);
  asm volatile ("nop"::"S"(405):);
  asm volatile ("movl %0, %1"::"r"(id), "m"(a):);
  p[2] = 8;
  memset(p, c, size);
  return bar(p);

}


Repository:
  rG LLVM Github Monorepo

https://reviews.llvm.org/D144439

Files:
  llvm/include/llvm/CodeGen/MachineFrameInfo.h
  llvm/include/llvm/CodeGen/TargetRegisterInfo.h
  llvm/lib/CodeGen/SelectionDAG/SelectionDAGBuilder.cpp
  llvm/lib/Target/X86/X86RegisterInfo.cpp
  llvm/lib/Target/X86/X86RegisterInfo.h
  llvm/test/CodeGen/X86/i386-baseptr.ll
  llvm/test/CodeGen/X86/swifttail-realign.ll
  llvm/test/CodeGen/X86/x86-64-baseptr.ll

-------------- next part --------------
A non-text attachment was scrubbed...
Name: D144439.498975.patch
Type: text/x-patch
Size: 9049 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/llvm-commits/attachments/20230221/3afba8e0/attachment.bin>


More information about the llvm-commits mailing list