In D140939 the following issue was introduced:
multiclass ATOMIC_LOGIC_OP_RM<bits<8> Opc8, string s> { let Defs = [EFLAGS], mayLoad = 1, mayStore = 1, isCodeGenOnly = 1, SchedRW = [WriteBitTestSetRegRMW] in { def 16rm : Ii8<Opc8, MRMDestMem, (outs), (ins i16mem:$src1, GR16:$src2), -------> Type Ii8 !strconcat(s, "{w}\t{$src2, $src1|$src1, $src2}"), [(set EFLAGS, (!cast<SDNode>("x86_rm_" # s) addr:$src1, GR16:$src2))]>, OpSize16, TB, LOCK; def 32rm : Ii8<Opc8, MRMDestMem, (outs), (ins i32mem:$src1, GR32:$src2), -------> Type Ii8 !strconcat(s, "{l}\t{$src2, $src1|$src1, $src2}"), [(set EFLAGS, (!cast<SDNode>("x86_rm_" # s) addr:$src1, GR32:$src2))]>, OpSize32, TB, LOCK; def 64rm : RIi8<Opc8, MRMDestMem, (outs), (ins i64mem:$src1, GR64:$src2), -------> Type RIi8 !strconcat(s, "{q}\t{$src2, $src1|$src1, $src2}"), [(set EFLAGS, (!cast<SDNode>("x86_rm_" # s) addr:$src1, GR64:$src2))]>, TB, LOCK; } }
As can be seen above, the ATOMIC_LOGIC_OP_RM definitions use the Ii8/RIi8 encoding, which makes the code emitted by the MC layer incorrect.
The problem can be observed in the test case I've added by looking at the value of the relocation, at the moment the value is off by 1 because of https://github.com/llvm/llvm-project/blob/34de7da6246cdfa6ff6f3d3c514583cddc0a10ec/llvm/lib/Target/X86/MCTargetDesc/X86MCCodeEmitter.cpp#L581. After applying my patch the relocation is as expected.
https://github.com/llvm/llvm-project/issues/61384
This patch fixes the issue and adds a regression test.
Copy + paste typo from the ATOMIC_LOGIC_OP above I suppose