Skip to content

Commit 9e86eed

Browse files
Added 8bit LEA support
1 parent 625135a commit 9e86eed

File tree

6 files changed

+54
-22
lines changed

6 files changed

+54
-22
lines changed

llvm/lib/Target/X86/X86ISelDAGToDAG.cpp

Lines changed: 11 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -3067,11 +3067,19 @@ bool X86DAGToDAGISel::selectLEA64_Addr(SDValue N, SDValue &Base, SDValue &Scale,
30673067
return false;
30683068

30693069
EVT BaseType = Base.getValueType();
3070-
unsigned SubReg = (BaseType == MVT::i16) ? X86::sub_16bit : X86::sub_32bit;
3070+
unsigned SubReg;
3071+
if (BaseType == MVT::i8)
3072+
SubReg = X86::sub_8bit;
3073+
else if (BaseType == MVT::i16)
3074+
SubReg = X86::sub_16bit;
3075+
else
3076+
SubReg = X86::sub_32bit;
3077+
30713078
auto *RN = dyn_cast<RegisterSDNode>(Base);
30723079
if (RN && RN->getReg() == 0)
30733080
Base = CurDAG->getRegister(0, MVT::i64);
3074-
else if ((BaseType == MVT::i16 || BaseType == MVT::i32) &&
3081+
else if ((BaseType == MVT::i8 || BaseType == MVT::i16 ||
3082+
BaseType == MVT::i32) &&
30753083
!isa<FrameIndexSDNode>(Base)) {
30763084
// Base could already be %rip, particularly in the x32 ABI.
30773085
SDValue ImplDef = SDValue(CurDAG->getMachineNode(X86::IMPLICIT_DEF, DL,
@@ -3085,7 +3093,7 @@ bool X86DAGToDAGISel::selectLEA64_Addr(SDValue N, SDValue &Base, SDValue &Scale,
30853093
Index = CurDAG->getRegister(0, MVT::i64);
30863094
else {
30873095
assert((IndexType == BaseType) &&
3088-
"Expect to be extending 16/32-bit registers for use in LEA");
3096+
"Expect to be extending 8/16/32-bit registers for use in LEA");
30893097
SDValue ImplDef = SDValue(CurDAG->getMachineNode(X86::IMPLICIT_DEF, DL,
30903098
MVT::i64), 0);
30913099
Index = CurDAG->getTargetInsertSubreg(SubReg, DL, MVT::i64, ImplDef, Index);

llvm/lib/Target/X86/X86InstrArithmetic.td

Lines changed: 17 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -25,17 +25,25 @@ let SchedRW = [WriteLEA] in {
2525
[(set GR32:$dst, lea32addr:$src)]>,
2626
OpSize32, Requires<[Not64BitMode]>;
2727

28-
def LEA64_16r : I<0x8D, MRMSrcMem, (outs GR16:$dst), (ins lea64_16mem:$src),
29-
"lea{w}\t{$src|$dst}, {$dst|$src}",
30-
[(set GR16:$dst, lea64_16addr:$src)]>,
31-
OpSize16,
32-
Requires<[In64BitMode]>;
28+
let Predicates = [HasNDD], isCodeGenOnly = 1 in {
29+
def LEA64_8r : I<0x8D, MRMSrcMem, (outs GR8:$dst), (ins lea64_8mem:$src),
30+
"lea{w}\t{$src|$dst}, {$dst|$src}",
31+
[(set GR8:$dst, lea64_iaddr:$src)]>,
32+
OpSize16,
33+
Requires<[In64BitMode]>;
34+
35+
def LEA64_16r : I<0x8D, MRMSrcMem, (outs GR16:$dst), (ins lea64_16mem:$src),
36+
"lea{w}\t{$src|$dst}, {$dst|$src}",
37+
[(set GR16:$dst, lea64_iaddr:$src)]>,
38+
OpSize16,
39+
Requires<[In64BitMode]>;
40+
}
3341

34-
def LEA64_32r : I<0x8D, MRMSrcMem,
35-
(outs GR32:$dst), (ins lea64_32mem:$src),
42+
def LEA64_32r : I<0x8D, MRMSrcMem, (outs GR32:$dst), (ins lea64_32mem:$src),
3643
"lea{l}\t{$src|$dst}, {$dst|$src}",
37-
[(set GR32:$dst, lea64_32addr:$src)]>,
38-
OpSize32, Requires<[In64BitMode]>;
44+
[(set GR32:$dst, lea64_iaddr:$src)]>,
45+
OpSize32,
46+
Requires<[In64BitMode]>;
3947

4048
let isReMaterializable = 1 in
4149
def LEA64r : RI<0x8D, MRMSrcMem, (outs GR64:$dst), (ins lea64mem:$src),

llvm/lib/Target/X86/X86InstrFragments.td

Lines changed: 5 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -357,16 +357,11 @@ def addr : ComplexPattern<iPTR, 5, "selectAddr">;
357357
def lea32addr : ComplexPattern<i32, 5, "selectLEAAddr",
358358
[add, sub, mul, X86mul_imm, shl, or, xor, frameindex],
359359
[]>;
360-
// In 64-bit mode 16-bit LEAs can use RIP-relative addressing.
361-
def lea64_16addr : ComplexPattern<i16, 5, "selectLEA64_Addr",
362-
[add, sub, mul, X86mul_imm, shl, or, xor,
363-
frameindex, X86WrapperRIP],
364-
[]>;
365-
// In 64-bit mode 32-bit LEAs can use RIP-relative addressing.
366-
def lea64_32addr : ComplexPattern<i32, 5, "selectLEA64_Addr",
367-
[add, sub, mul, X86mul_imm, shl, or, xor,
368-
frameindex, X86WrapperRIP],
369-
[]>;
360+
// In 64-bit mode 8/16/32-bit LEAs can use RIP-relative addressing.
361+
def lea64_iaddr : ComplexPattern<iAny, 5, "selectLEA64_Addr",
362+
[add, sub, mul, X86mul_imm, shl, or, xor,
363+
frameindex, X86WrapperRIP],
364+
[]>;
370365

371366
def tls32addr : ComplexPattern<i32, 5, "selectTLSADDRAddr",
372367
[tglobaltlsaddr], []>;

llvm/lib/Target/X86/X86InstrOperands.td

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -456,6 +456,12 @@ def i64u8imm : Operand<i64> {
456456
let OperandType = "OPERAND_IMMEDIATE";
457457
}
458458

459+
def lea64_8mem : Operand<i8> {
460+
let PrintMethod = "printMemReference";
461+
let MIOperandInfo = (ops GR64, i8imm, GR64_NOSP, i8imm, SEGMENT_REG);
462+
let ParserMatchClass = X86MemAsmOperand;
463+
}
464+
459465
def lea64_16mem : Operand<i16> {
460466
let PrintMethod = "printMemReference";
461467
let MIOperandInfo = (ops GR64, i8imm, GR64_NOSP, i16imm, SEGMENT_REG);

llvm/test/CodeGen/X86/lea-8bit.ll

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
; NOTE: Assertions have been autogenerated by utils/update_llc_test_checks.py UTC_ARGS: --version 5
2+
; RUN: llc < %s -mtriple=x86_64-linux -mattr=+ndd | FileCheck %s --check-prefixes=CHECK
3+
4+
define i8 @lea8bit(i8 %in) {
5+
; CHECK-LABEL: lea8bit:
6+
; CHECK: # %bb.0:
7+
; CHECK-NEXT: # kill: def $edi killed $edi def $rdi
8+
; CHECK-NEXT: leaw 1(%rdi,%rdi), %al
9+
; CHECK-NEXT: retq
10+
%shl = shl i8 %in, 1
11+
%or = or disjoint i8 %shl, 1
12+
ret i8 %or
13+
}

llvm/utils/TableGen/X86RecognizableInstr.cpp

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1096,6 +1096,7 @@ OperandType RecognizableInstr::typeFromString(const std::string &s,
10961096
TYPE("brtarget16", TYPE_REL)
10971097
TYPE("brtarget8", TYPE_REL)
10981098
TYPE("f80mem", TYPE_M)
1099+
TYPE("lea64_8mem", TYPE_M)
10991100
TYPE("lea64_16mem", TYPE_M)
11001101
TYPE("lea64_32mem", TYPE_M)
11011102
TYPE("lea64mem", TYPE_M)
@@ -1365,6 +1366,7 @@ RecognizableInstr::memoryEncodingFromString(const std::string &s,
13651366
ENCODING("i512mem_GR32", ENCODING_RM)
13661367
ENCODING("i512mem_GR64", ENCODING_RM)
13671368
ENCODING("f80mem", ENCODING_RM)
1369+
ENCODING("lea64_8mem", ENCODING_RM)
13681370
ENCODING("lea64_16mem", ENCODING_RM)
13691371
ENCODING("lea64_32mem", ENCODING_RM)
13701372
ENCODING("lea64mem", ENCODING_RM)

0 commit comments

Comments
 (0)