Fix 64-bit immediate patterns.

llvm-svn: 146059
This commit is contained in:
Akira Hatanaka 2011-12-07 20:10:24 +00:00
parent 268b95034c
commit 19d6cd4d0e
4 changed files with 60 additions and 6 deletions

View File

@ -25,7 +25,7 @@ def uimm16_64 : Operand<i64> {
// Transformation Function - get Imm - 32.
def Subtract32 : SDNodeXForm<imm, [{
return getI32Imm((unsigned)N->getZExtValue() - 32);
return getImm(N, (unsigned)N->getZExtValue() - 32);
}]>;
// shamt field must fit in 5 bits.
@ -36,6 +36,19 @@ def imm32_63 : ImmLeaf<i32,
[{return (int32_t)Imm >= 32 && (int32_t)Imm < 64;}],
Subtract32>;
// Is a 32-bit int.
def immSExt32 : ImmLeaf<i64, [{return isInt<32>(Imm);}]>;
// Transformation Function - get the higher 16 bits.
def HIGHER : SDNodeXForm<imm, [{
return getImm(N, (N->getZExtValue() >> 32) & 0xFFFF);
}]>;
// Transformation Function - get the highest 16 bits.
def HIGHEST : SDNodeXForm<imm, [{
return getImm(N, (N->getZExtValue() >> 48) & 0xFFFF);
}]>;
//===----------------------------------------------------------------------===//
// Instructions specific format
//===----------------------------------------------------------------------===//
@ -219,9 +232,15 @@ def : Pat<(i64 immSExt16:$in),
def : Pat<(i64 immZExt16:$in),
(ORi64 ZERO_64, imm:$in)>;
// 32-bit immediates
def : Pat<(i64 immSExt32:$imm),
(ORi64 (LUi64 (HI16 imm:$imm)), (LO16 imm:$imm))>;
// Arbitrary immediates
def : Pat<(i64 imm:$imm),
(ORi64 (LUi64 (HI16 imm:$imm)), (LO16 imm:$imm))>;
(ORi64 (DSLL (ORi64 (DSLL (ORi64 (LUi64 (HIGHEST imm:$imm)),
(HIGHER imm:$imm)), 16), (HI16 imm:$imm)), 16),
(LO16 imm:$imm))>;
// extended loads
let Predicates = [NotN64] in {

View File

@ -88,8 +88,8 @@ private:
// getI32Imm - Return a target constant with the specified
// value, of type i32.
inline SDValue getI32Imm(unsigned Imm) {
return CurDAG->getTargetConstant(Imm, MVT::i32);
inline SDValue getImm(const SDNode *Node, unsigned Imm) {
return CurDAG->getTargetConstant(Imm, Node->getValueType(0));
}
virtual bool SelectInlineAsmMemoryOperand(const SDValue &Op,

View File

@ -194,12 +194,12 @@ def size_ins : Operand<i32> {
// Transformation Function - get the lower 16 bits.
def LO16 : SDNodeXForm<imm, [{
return getI32Imm((unsigned)N->getZExtValue() & 0xFFFF);
return getImm(N, N->getZExtValue() & 0xFFFF);
}]>;
// Transformation Function - get the higher 16 bits.
def HI16 : SDNodeXForm<imm, [{
return getI32Imm((unsigned)N->getZExtValue() >> 16);
return getImm(N, (N->getZExtValue() >> 16) & 0xFFFF);
}]>;
// Node immediate fits as 16-bit sign extended on target immediate.

View File

@ -0,0 +1,35 @@
; RUN: llc -march=mips64el -mcpu=mips64 < %s | FileCheck %s
define i64 @foo3() nounwind readnone {
entry:
; CHECK: foo3
; CHECK: lui $[[R0:[0-9]+]], 4660
; CHECK: ori ${{[0-9]+}}, $[[R0]], 22136
ret i64 305419896
}
define i64 @foo6() nounwind readnone {
entry:
; CHECK: foo6
; CHECK: ori ${{[0-9]+}}, $zero, 33332
ret i64 33332
}
define i64 @foo7() nounwind readnone {
entry:
; CHECK: foo7
; CHECK: daddiu ${{[0-9]+}}, $zero, -32204
ret i64 -32204
}
define i64 @foo9() nounwind readnone {
entry:
; CHECK: foo9
; CHECK: lui $[[R0:[0-9]+]], 4660
; CHECK: ori $[[R1:[0-9]+]], $[[R0]], 22136
; CHECK: dsll $[[R2:[0-9]+]], $[[R1]], 16
; CHECK: ori $[[R3:[0-9]+]], $[[R2]], 36882
; CHECK: dsll $[[R4:[0-9]+]], $[[R3]], 16
; CHECK: ori ${{[0-9]+}}, $[[R4]], 13398
ret i64 1311768467284833366
}