]> granicus.if.org Git - llvm/commit
Merging r263325:
authorTom Stellard <thomas.stellard@amd.com>
Wed, 4 May 2016 16:38:57 +0000 (16:38 +0000)
committerTom Stellard <thomas.stellard@amd.com>
Wed, 4 May 2016 16:38:57 +0000 (16:38 +0000)
commitef1b1eb3e06ad233efa8404e8c1cc31e7b734059
tree714a6ef57be066ec72dba417d663afacc3a3a32d
parent06cf4b238fa45638ed37ec7725d38930fea37ff9
Merging r263325:
------------------------------------------------------------------------
r263325 | qcolombet | 2016-03-11 18:25:27 -0800 (Fri, 11 Mar 2016) | 40 lines

[X86] Make sure we do not clobber RBX with cmpxchg when used as a base pointer.

cmpxchg[8|16]b uses RBX as one of its argument.
In other words, using this instruction clobbers RBX as it is defined to hold one
the input. When the backend uses dynamically allocated stack, RBX is
used as a reserved register for the base pointer.

Reserved registers have special semantic that only the target understands and
enforces, because of that, the register allocator don’t use them, but also,
don’t try to make sure they are used properly (remember it does not know how
they are supposed to be used).

Therefore, when RBX is used as a reserved register but defined by something that
is not compatible with that use, the register allocator will not fix the
surrounding code to make sure it gets saved and restored properly around the
broken code. This is the responsibility of the target to do the right thing with
its reserved register.

To fix that, when the base pointer needs to be preserved, we use a different
pseudo instruction for cmpxchg that save rbx.
That pseudo takes two more arguments than the regular instruction:
- One is the value to be copied into RBX to set the proper value for the
  comparison.
- The other is the virtual register holding the save of the value of RBX as the
  base pointer. This saving is done as part of isel (i.e., we emit a copy from
  rbx).

cmpxchg_save_rbx <regular cmpxchg args>, input_for_rbx_reg, save_of_rbx_as_bp

This gets expanded into:
rbx = copy input_for_rbx_reg
cmpxchg <regular cmpxchg args>
rbx = save_of_rbx_as_bp

Note: The actual modeling of the pseudo is a bit more complicated to make sure
the interferes that appears after the pseudo gets expanded are properly modeled
before that expansion.

This fixes PR26883.

------------------------------------------------------------------------

git-svn-id: https://llvm.org/svn/llvm-project/llvm/branches/release_38@268518 91177308-0d34-0410-b5e6-96231b3b80d8
lib/Target/X86/X86ExpandPseudo.cpp
lib/Target/X86/X86ISelLowering.cpp
lib/Target/X86/X86ISelLowering.h
lib/Target/X86/X86InstrCompiler.td
lib/Target/X86/X86InstrInfo.td
test/CodeGen/X86/atomic128.ll
test/CodeGen/X86/base-pointer-and-cmpxchg.ll [new file with mode: 0644]