diff options
| author | Nemanja Ivanovic <nemanja.i.ibm@gmail.com> | 2017-02-24 18:16:06 +0000 |
|---|---|---|
| committer | Nemanja Ivanovic <nemanja.i.ibm@gmail.com> | 2017-02-24 18:16:06 +0000 |
| commit | 195c5452d391903f57827532b964d25a7c82ebdf (patch) | |
| tree | 28aa4143b8d1c101c84f7cff91e84b41846dd3db /llvm | |
| parent | 82d53ed492bebd2a585fa4c37efc81ad1d6f68d9 (diff) | |
| download | bcm5719-llvm-195c5452d391903f57827532b964d25a7c82ebdf.tar.gz bcm5719-llvm-195c5452d391903f57827532b964d25a7c82ebdf.zip | |
[PowerPC] Use subfic instruction for subtract from immediate
Provide a 64-bit pattern to use SUBFIC for subtracting from a 16-bit immediate.
The corresponding pattern already exists for 32-bit integers.
Committing on behalf of Hiroshi Inoue.
Differential Revision: https://reviews.llvm.org/D29387
llvm-svn: 296144
Diffstat (limited to 'llvm')
| -rw-r--r-- | llvm/lib/Target/PowerPC/PPCInstr64Bit.td | 4 | ||||
| -rw-r--r-- | llvm/test/CodeGen/PowerPC/subtract_from_imm.ll | 41 |
2 files changed, 45 insertions, 0 deletions
diff --git a/llvm/lib/Target/PowerPC/PPCInstr64Bit.td b/llvm/lib/Target/PowerPC/PPCInstr64Bit.td index 0f12aa1aaa8..997b96ca6ec 100644 --- a/llvm/lib/Target/PowerPC/PPCInstr64Bit.td +++ b/llvm/lib/Target/PowerPC/PPCInstr64Bit.td @@ -1232,6 +1232,10 @@ def : Pat<(srl i64:$rS, i32:$rB), 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))>; diff --git a/llvm/test/CodeGen/PowerPC/subtract_from_imm.ll b/llvm/test/CodeGen/PowerPC/subtract_from_imm.ll new file mode 100644 index 00000000000..8fa07b671a3 --- /dev/null +++ b/llvm/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 +} + |

