Skip to content

Commit 9027ee6

Browse files
authored
[X86][MC] Support encoding optimization & assembler relaxation about immediate operands for CCMP (#85175)
1 parent cbd8031 commit 9027ee6

File tree

3 files changed

+22
-1
lines changed

3 files changed

+22
-1
lines changed

llvm/lib/Target/X86/MCTargetDesc/X86AsmBackend.cpp

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -723,9 +723,10 @@ void X86AsmBackend::applyFixup(const MCAssembler &Asm, const MCFixup &Fixup,
723723
bool X86AsmBackend::mayNeedRelaxation(const MCInst &MI,
724724
const MCSubtargetInfo &STI) const {
725725
unsigned Opcode = MI.getOpcode();
726+
unsigned SkipOperands = X86::isCCMPCC(Opcode) ? 2 : 0;
726727
return isRelaxableBranch(Opcode) ||
727728
(X86::getOpcodeForLongImmediateForm(Opcode) != Opcode &&
728-
MI.getOperand(MI.getNumOperands() - 1).isExpr());
729+
MI.getOperand(MI.getNumOperands() - 1 - SkipOperands).isExpr());
729730
}
730731

731732
bool X86AsmBackend::fixupNeedsRelaxation(const MCFixup &Fixup,

llvm/lib/Target/X86/MCTargetDesc/X86EncodingOptimizationForImmediate.def

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,12 @@ ENTRY(CMP32mi, CMP32mi8)
1818
ENTRY(CMP32ri, CMP32ri8)
1919
ENTRY(CMP64mi32, CMP64mi8)
2020
ENTRY(CMP64ri32, CMP64ri8)
21+
ENTRY(CCMP16mi, CCMP16mi8)
22+
ENTRY(CCMP16ri, CCMP16ri8)
23+
ENTRY(CCMP32mi, CCMP32mi8)
24+
ENTRY(CCMP32ri, CCMP32ri8)
25+
ENTRY(CCMP64mi32, CCMP64mi8)
26+
ENTRY(CCMP64ri32, CCMP64ri8)
2127
ENTRY(PUSH16i, PUSH16i8)
2228
ENTRY(PUSH32i, PUSH32i8)
2329
ENTRY(PUSH64i32, PUSH64i8)

llvm/test/MC/X86/apx/ccmp-reloc.s

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
// RUN: llvm-mc -triple x86_64-linux-gnu -filetype=obj %s | llvm-readobj -r - | FileCheck %s
2+
3+
// CHECK: Relocations [
4+
// CHECK-NEXT: Section ({{[0-9]+}}) .rela.text {
5+
ccmpbb {dfv=of} $foo, %bl // CHECK-NEXT: R_X86_64_8
6+
ccmpbb {dfv=of} $foo, 123(%r8,%rax,4) // CHECK-NEXT: R_X86_64_8
7+
ccmpbw {dfv=of} $foo, %bx // CHECK-NEXT: R_X86_64_16
8+
ccmpbw {dfv=of} $foo, 123(%r8,%rax,4) // CHECK-NEXT: R_X86_64_16
9+
ccmpbl {dfv=of} $foo, %ebx // CHECK-NEXT: R_X86_64_32
10+
ccmpbl {dfv=of} $foo, 123(%r8,%rax,4) // CHECK-NEXT: R_X86_64_32
11+
ccmpbq {dfv=of} $foo, %rbx // CHECK-NEXT: R_X86_64_32S
12+
ccmpbq {dfv=of} $foo, 123(%r8,%rax,4) // CHECK-NEXT: R_X86_64_32S
13+
// CHECK-NEXT: }
14+
// CHECK-NEXT: ]

0 commit comments

Comments
 (0)