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

Hiroshi Inoue via Phabricator via llvm-commits llvm-commits at lists.llvm.org
Wed Feb 1 03:37:52 PST 2017


inouehrs created this revision.

- generate `subfic` instruction for subtracting a value in a GPR from a 16-bit immediate (e.g. x = 64 - y); currently LLVM generates two instructions (load immediate + subtract) for this purpose
- add a unit test to confirm that `subfic` is used if possible


https://reviews.llvm.org/D29387

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


Index: test/CodeGen/PowerPC/subtract_from_imm.ll
===================================================================
--- /dev/null
+++ test/CodeGen/PowerPC/subtract_from_imm.ll
@@ -0,0 +1,43 @@
+; RUN: llc -verify-machineinstrs < %s | FileCheck %s
+
+target datalayout = "E-p:64:64:64-i1:8:8-i8:8:8-i16:16:16-i32:32:32-i64:64:64-f32:32:32-f64:64:64-v128:128:128-n32:64"
+target triple = "powerpc64-unknown-linux-gnu"
+
+; 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: lib/Target/PowerPC/PPCInstr64Bit.td
===================================================================
--- lib/Target/PowerPC/PPCInstr64Bit.td
+++ 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.86604.patch
Type: text/x-patch
Size: 1724 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/llvm-commits/attachments/20170201/b2cdfa7a/attachment.bin>


More information about the llvm-commits mailing list