[PATCH] D29387: [PPC] Use subfic instruction for subtract from immediate

Nemanja Ivanovic via Phabricator via llvm-commits llvm-commits at lists.llvm.org
Fri Feb 24 10:28:02 PST 2017


This revision was automatically updated to reflect the committed changes.
Closed by commit rL296144: [PowerPC] Use subfic instruction for subtract from immediate (authored by nemanjai).

Changed prior to commit:
  https://reviews.llvm.org/D29387?vs=86771&id=89691#toc

Repository:
  rL LLVM

https://reviews.llvm.org/D29387

Files:
  llvm/trunk/lib/Target/PowerPC/PPCInstr64Bit.td
  llvm/trunk/test/CodeGen/PowerPC/subtract_from_imm.ll


Index: llvm/trunk/test/CodeGen/PowerPC/subtract_from_imm.ll
===================================================================
--- llvm/trunk/test/CodeGen/PowerPC/subtract_from_imm.ll
+++ llvm/trunk/test/CodeGen/PowerPC/subtract_from_imm.ll
@@ -0,0 +1,41 @@
+; RUN: llc -verify-machineinstrs -mtriple=powerpc64le-unknown-linux-gnu < %s | FileCheck %s
+; RUN: llc -verify-machineinstrs -mtriple=powerpc64-unknown-linux-gnu < %s | FileCheck %s
+
+; Make sure that the subfic is generated iff possible
+
+define i64 @subtract_from_imm1(i64 %v) nounwind readnone {
+entry:
+; CHECK-LABEL: subtract_from_imm1
+; CHECK: subfic 3, 3, 32767
+; CHECK: blr
+  %sub = sub i64 32767, %v
+  ret i64 %sub
+}
+
+define i64 @subtract_from_imm2(i64 %v) nounwind readnone {
+entry:
+; CHECK-LABEL: subtract_from_imm2
+; CHECK-NOT: subfic
+; CHECK: blr
+  %sub = sub i64 32768, %v
+  ret i64 %sub
+}
+
+define i64 @subtract_from_imm3(i64 %v) nounwind readnone {
+entry:
+; CHECK-LABEL: subtract_from_imm3
+; CHECK: subfic 3, 3, -32768
+; CHECK: blr
+  %sub = sub i64 -32768, %v
+  ret i64 %sub
+}
+
+define i64 @subtract_from_imm4(i64 %v) nounwind readnone {
+entry:
+; CHECK-LABEL: subtract_from_imm4
+; CHECK-NOT: subfic
+; CHECK: blr
+  %sub = sub i64 -32769, %v
+  ret i64 %sub
+}
+
Index: llvm/trunk/lib/Target/PowerPC/PPCInstr64Bit.td
===================================================================
--- llvm/trunk/lib/Target/PowerPC/PPCInstr64Bit.td
+++ llvm/trunk/lib/Target/PowerPC/PPCInstr64Bit.td
@@ -1232,6 +1232,10 @@
 def : Pat<(shl i64:$rS, i32:$rB),
           (SLD $rS, $rB)>;
 
+// SUBFIC
+def : Pat<(sub imm64SExt16:$imm, i64:$in),
+          (SUBFIC8 $in, imm:$imm)>;
+
 // SHL/SRL
 def : Pat<(shl i64:$in, (i32 imm:$imm)),
           (RLDICR $in, imm:$imm, (SHL64 imm:$imm))>;


-------------- next part --------------
A non-text attachment was scrubbed...
Name: D29387.89691.patch
Type: text/x-patch
Size: 1783 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/llvm-commits/attachments/20170224/cadf59cb/attachment.bin>


More information about the llvm-commits mailing list