[llvm] 9027ee6 - [X86][MC] Support encoding optimization & assembler relaxation about immediate operands for CCMP (#85175)
via llvm-commits
llvm-commits at lists.llvm.org
Sun May 26 21:29:46 PDT 2024
Author: Freddy Ye
Date: 2024-05-27T12:29:43+08:00
New Revision: 9027ee63f9d8b02d3ef3d5815d98027a8b513997
URL: https://github.com/llvm/llvm-project/commit/9027ee63f9d8b02d3ef3d5815d98027a8b513997
DIFF: https://github.com/llvm/llvm-project/commit/9027ee63f9d8b02d3ef3d5815d98027a8b513997.diff
LOG: [X86][MC] Support encoding optimization & assembler relaxation about immediate operands for CCMP (#85175)
Added:
llvm/test/MC/X86/apx/ccmp-reloc.s
Modified:
llvm/lib/Target/X86/MCTargetDesc/X86AsmBackend.cpp
llvm/lib/Target/X86/MCTargetDesc/X86EncodingOptimizationForImmediate.def
Removed:
################################################################################
diff --git a/llvm/lib/Target/X86/MCTargetDesc/X86AsmBackend.cpp b/llvm/lib/Target/X86/MCTargetDesc/X86AsmBackend.cpp
index 99dc9797f6df9..472f34a4efdb4 100644
--- a/llvm/lib/Target/X86/MCTargetDesc/X86AsmBackend.cpp
+++ b/llvm/lib/Target/X86/MCTargetDesc/X86AsmBackend.cpp
@@ -723,9 +723,10 @@ void X86AsmBackend::applyFixup(const MCAssembler &Asm, const MCFixup &Fixup,
bool X86AsmBackend::mayNeedRelaxation(const MCInst &MI,
const MCSubtargetInfo &STI) const {
unsigned Opcode = MI.getOpcode();
+ unsigned SkipOperands = X86::isCCMPCC(Opcode) ? 2 : 0;
return isRelaxableBranch(Opcode) ||
(X86::getOpcodeForLongImmediateForm(Opcode) != Opcode &&
- MI.getOperand(MI.getNumOperands() - 1).isExpr());
+ MI.getOperand(MI.getNumOperands() - 1 - SkipOperands).isExpr());
}
bool X86AsmBackend::fixupNeedsRelaxation(const MCFixup &Fixup,
diff --git a/llvm/lib/Target/X86/MCTargetDesc/X86EncodingOptimizationForImmediate.def b/llvm/lib/Target/X86/MCTargetDesc/X86EncodingOptimizationForImmediate.def
index 27b6a654e6eb7..f3997a092e459 100644
--- a/llvm/lib/Target/X86/MCTargetDesc/X86EncodingOptimizationForImmediate.def
+++ b/llvm/lib/Target/X86/MCTargetDesc/X86EncodingOptimizationForImmediate.def
@@ -18,6 +18,12 @@ ENTRY(CMP32mi, CMP32mi8)
ENTRY(CMP32ri, CMP32ri8)
ENTRY(CMP64mi32, CMP64mi8)
ENTRY(CMP64ri32, CMP64ri8)
+ENTRY(CCMP16mi, CCMP16mi8)
+ENTRY(CCMP16ri, CCMP16ri8)
+ENTRY(CCMP32mi, CCMP32mi8)
+ENTRY(CCMP32ri, CCMP32ri8)
+ENTRY(CCMP64mi32, CCMP64mi8)
+ENTRY(CCMP64ri32, CCMP64ri8)
ENTRY(PUSH16i, PUSH16i8)
ENTRY(PUSH32i, PUSH32i8)
ENTRY(PUSH64i32, PUSH64i8)
diff --git a/llvm/test/MC/X86/apx/ccmp-reloc.s b/llvm/test/MC/X86/apx/ccmp-reloc.s
new file mode 100644
index 0000000000000..6b9d11f26da86
--- /dev/null
+++ b/llvm/test/MC/X86/apx/ccmp-reloc.s
@@ -0,0 +1,14 @@
+// RUN: llvm-mc -triple x86_64-linux-gnu -filetype=obj %s | llvm-readobj -r - | FileCheck %s
+
+// CHECK: Relocations [
+// CHECK-NEXT: Section ({{[0-9]+}}) .rela.text {
+ccmpbb {dfv=of} $foo, %bl // CHECK-NEXT: R_X86_64_8
+ccmpbb {dfv=of} $foo, 123(%r8,%rax,4) // CHECK-NEXT: R_X86_64_8
+ccmpbw {dfv=of} $foo, %bx // CHECK-NEXT: R_X86_64_16
+ccmpbw {dfv=of} $foo, 123(%r8,%rax,4) // CHECK-NEXT: R_X86_64_16
+ccmpbl {dfv=of} $foo, %ebx // CHECK-NEXT: R_X86_64_32
+ccmpbl {dfv=of} $foo, 123(%r8,%rax,4) // CHECK-NEXT: R_X86_64_32
+ccmpbq {dfv=of} $foo, %rbx // CHECK-NEXT: R_X86_64_32S
+ccmpbq {dfv=of} $foo, 123(%r8,%rax,4) // CHECK-NEXT: R_X86_64_32S
+// CHECK-NEXT: }
+// CHECK-NEXT: ]
More information about the llvm-commits
mailing list