From 73c5f80ec9913c9bd14955c0bd1dc8a62778f21a Mon Sep 17 00:00:00 2001 From: Jakob Stoklund Olesen Date: Tue, 2 Apr 2013 04:09:23 +0000 Subject: [PATCH] Basic 64-bit ALU operations. SPARC v9 extends all ALU instructions to 64 bits, so we simply need to add patterns to use them for both i32 and i64 values. git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@178527 91177308-0d34-0410-b5e6-96231b3b80d8 --- lib/Target/Sparc/SparcInstr64Bit.td | 38 +++++++++++++++++++++++++++++ test/CodeGen/SPARC/64bit.ll | 21 ++++++++++++++++ 2 files changed, 59 insertions(+) diff --git a/lib/Target/Sparc/SparcInstr64Bit.td b/lib/Target/Sparc/SparcInstr64Bit.td index 5ab7b1f8837..c7f63cd486f 100644 --- a/lib/Target/Sparc/SparcInstr64Bit.td +++ b/lib/Target/Sparc/SparcInstr64Bit.td @@ -133,3 +133,41 @@ def : Pat<(i64 imm:$val), (ORrr (SLLXri (ORri (SETHIi (HH22 $val)), (HM10 $val)), (i64 32)), (ORri (SETHIi (HI22 $val)), (LO10 $val)))>, Requires<[Is64Bit]>; + + +//===----------------------------------------------------------------------===// +// 64-bit Integer Arithmetic and Logic. +//===----------------------------------------------------------------------===// + +let Predicates = [Is64Bit] in { + +// Register-register instructions. + +def : Pat<(and i64:$a, i64:$b), (ANDrr $a, $b)>; +def : Pat<(or i64:$a, i64:$b), (ORrr $a, $b)>; +def : Pat<(xor i64:$a, i64:$b), (XORrr $a, $b)>; + +def : Pat<(and i64:$a, (not i64:$b)), (ANDNrr $a, $b)>; +def : Pat<(or i64:$a, (not i64:$b)), (ORNrr $a, $b)>; +def : Pat<(xor i64:$a, (not i64:$b)), (XNORrr $a, $b)>; + +def : Pat<(add i64:$a, i64:$b), (ADDrr $a, $b)>; +def : Pat<(sub i64:$a, i64:$b), (SUBrr $a, $b)>; + +// Add/sub with carry were renamed to addc/subc in SPARC v9. +def : Pat<(adde i64:$a, i64:$b), (ADDXrr $a, $b)>; +def : Pat<(sube i64:$a, i64:$b), (SUBXrr $a, $b)>; + +def : Pat<(addc i64:$a, i64:$b), (ADDCCrr $a, $b)>; +def : Pat<(subc i64:$a, i64:$b), (SUBCCrr $a, $b)>; + +// Register-immediate instructions. + +def : Pat<(and i64:$a, (i64 simm13:$b)), (ANDri $a, (as_i32imm $b))>; +def : Pat<(or i64:$a, (i64 simm13:$b)), (ORri $a, (as_i32imm $b))>; +def : Pat<(xor i64:$a, (i64 simm13:$b)), (XORri $a, (as_i32imm $b))>; + +def : Pat<(add i64:$a, (i64 simm13:$b)), (ADDri $a, (as_i32imm $b))>; +def : Pat<(sub i64:$a, (i64 simm13:$b)), (SUBri $a, (as_i32imm $b))>; + +} // Predicates = [Is64Bit] diff --git a/test/CodeGen/SPARC/64bit.ll b/test/CodeGen/SPARC/64bit.ll index b0c9852ef25..b5260a5a6f8 100644 --- a/test/CodeGen/SPARC/64bit.ll +++ b/test/CodeGen/SPARC/64bit.ll @@ -65,3 +65,24 @@ define i64 @ret_nimm33() { define i64 @ret_bigimm() { ret i64 6800754272627607872 } + +; CHECK: reg_reg_alu +; CHECK: add %i0, %i1, [[R0:%[goli][0-7]]] +; CHECK: sub [[R0]], %i2, [[R1:%[goli][0-7]]] +; CHECK: andn [[R1]], %i0, %i0 +define i64 @reg_reg_alu(i64 %x, i64 %y, i64 %z) { + %a = add i64 %x, %y + %b = sub i64 %a, %z + %c = xor i64 %x, -1 + %d = and i64 %b, %c + ret i64 %d +} + +; CHECK: reg_imm_alu +; CHECK: add %i0, -5, [[R0:%[goli][0-7]]] +; CHECK: xor [[R0]], 2, %i0 +define i64 @reg_imm_alu(i64 %x, i64 %y, i64 %z) { + %a = add i64 %x, -5 + %b = xor i64 %a, 2 + ret i64 %b +}