[llvm] e6a39e8 - [X86][NFC] Compress CD8_Scale from 7 bits to 3 bits
Shengchen Kan via llvm-commits
llvm-commits at lists.llvm.org
Mon Apr 3 23:24:52 PDT 2023
Author: Shengchen Kan
Date: 2023-04-04T14:24:45+08:00
New Revision: e6a39e807582d9e911834bedb952fb3038eec217
URL: https://github.com/llvm/llvm-project/commit/e6a39e807582d9e911834bedb952fb3038eec217
DIFF: https://github.com/llvm/llvm-project/commit/e6a39e807582d9e911834bedb952fb3038eec217.diff
LOG: [X86][NFC] Compress CD8_Scale from 7 bits to 3 bits
Post: https://discourse.llvm.org/t/save-some-bits-in-tsflags-for-x86/69025
Reviewed By: craig.topper
Differential Revision: https://reviews.llvm.org/D147500
Added:
Modified:
llvm/lib/Target/X86/MCTargetDesc/X86BaseInfo.h
llvm/lib/Target/X86/MCTargetDesc/X86MCCodeEmitter.cpp
llvm/lib/Target/X86/X86InstrFormats.td
Removed:
################################################################################
diff --git a/llvm/lib/Target/X86/MCTargetDesc/X86BaseInfo.h b/llvm/lib/Target/X86/MCTargetDesc/X86BaseInfo.h
index 3bf1e3244664d..e2293fe30561f 100644
--- a/llvm/lib/Target/X86/MCTargetDesc/X86BaseInfo.h
+++ b/llvm/lib/Target/X86/MCTargetDesc/X86BaseInfo.h
@@ -955,10 +955,10 @@ namespace X86II {
// The scaling factor for the AVX512's 8-bit compressed displacement.
CD8_Scale_Shift = EVEX_BShift + 1,
- CD8_Scale_Mask = 127ULL << CD8_Scale_Shift,
+ CD8_Scale_Mask = 7ULL << CD8_Scale_Shift,
/// Explicitly specified rounding control
- EVEX_RCShift = CD8_Scale_Shift + 7,
+ EVEX_RCShift = CD8_Scale_Shift + 3,
EVEX_RC = 1ULL << EVEX_RCShift,
// NOTRACK prefix
diff --git a/llvm/lib/Target/X86/MCTargetDesc/X86MCCodeEmitter.cpp b/llvm/lib/Target/X86/MCTargetDesc/X86MCCodeEmitter.cpp
index 8325ab917fee6..04e551de24cb0 100644
--- a/llvm/lib/Target/X86/MCTargetDesc/X86MCCodeEmitter.cpp
+++ b/llvm/lib/Target/X86/MCTargetDesc/X86MCCodeEmitter.cpp
@@ -317,16 +317,17 @@ static void emitConstant(uint64_t Val, unsigned Size, raw_ostream &OS) {
static bool isDispOrCDisp8(uint64_t TSFlags, int Value, int &ImmOffset) {
bool HasEVEX = (TSFlags & X86II::EncodingMask) == X86II::EVEX;
- int CD8_Scale =
+ unsigned CD8_Scale =
(TSFlags & X86II::CD8_Scale_Mask) >> X86II::CD8_Scale_Shift;
- if (!HasEVEX || CD8_Scale == 0)
+ CD8_Scale = CD8_Scale ? 1U << (CD8_Scale - 1) : 0U;
+ if (!HasEVEX || !CD8_Scale)
return isInt<8>(Value);
assert(isPowerOf2_32(CD8_Scale) && "Unexpected CD8 scale!");
if (Value & (CD8_Scale - 1)) // Unaligned offset
return false;
- int CDisp8 = Value / CD8_Scale;
+ int CDisp8 = Value / static_cast<int>(CD8_Scale);
if (!isInt<8>(CDisp8))
return false;
diff --git a/llvm/lib/Target/X86/X86InstrFormats.td b/llvm/lib/Target/X86/X86InstrFormats.td
index f08f81358349b..dffb25ad6509e 100644
--- a/llvm/lib/Target/X86/X86InstrFormats.td
+++ b/llvm/lib/Target/X86/X86InstrFormats.td
@@ -388,11 +388,10 @@ class X86Inst<bits<8> opcod, Format f, ImmType i, dag outs, dag ins,
let TSFlags{42} = hasEVEX_Z;
let TSFlags{43} = hasEVEX_L2;
let TSFlags{44} = hasEVEX_B;
- // If we run out of TSFlags bits, it's possible to encode this in 3 bits.
- let TSFlags{51-45} = CD8_Scale;
- let TSFlags{52} = hasEVEX_RC;
- let TSFlags{53} = hasNoTrackPrefix;
- let TSFlags{54} = ExplicitVEXPrefix;
+ let TSFlags{47-45} = !if(!eq(CD8_Scale, 0), 0, !add(!logtwo(CD8_Scale), 1));
+ let TSFlags{48} = hasEVEX_RC;
+ let TSFlags{49} = hasNoTrackPrefix;
+ let TSFlags{50} = ExplicitVEXPrefix;
}
class PseudoI<dag oops, dag iops, list<dag> pattern>
More information about the llvm-commits
mailing list