From df40f8e8ad0aa93defa44b8a136e8d871cfd44ea Mon Sep 17 00:00:00 2001 From: Richard Sandiford Date: Wed, 21 Aug 2013 09:34:56 +0000 Subject: [SystemZ] Define remainig *MUL_LOHI patterns The initial port used MLG(R) for i64 UMUL_LOHI but left the other three combinations as not-legal-or-custom. Although 32x32->{32,32} multiplications exist, they're not as quick as doing a normal 64-bit multiplication, so it didn't seem like i32 SMUL_LOHI and UMUL_LOHI would be useful. There's also no direct instruction for i64 SMUL_LOHI, so it needs to be implemented in terms of UMUL_LOHI. However, not defining these patterns means that we don't convert division by a constant into multiplication, so this patch fills in the other cases. The new i64 SMUL_LOHI sequence is simpler than the one that we used previously for 64x64->128 multiplication, so int-mul-08.ll now tests the full sequence. git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@188898 91177308-0d34-0410-b5e6-96231b3b80d8 --- test/CodeGen/SystemZ/int-div-06.ll | 56 ++++++++++++++++++++++++++++++++++++++ test/CodeGen/SystemZ/int-mul-08.ll | 10 +++++-- 2 files changed, 63 insertions(+), 3 deletions(-) create mode 100644 test/CodeGen/SystemZ/int-div-06.ll (limited to 'test/CodeGen') diff --git a/test/CodeGen/SystemZ/int-div-06.ll b/test/CodeGen/SystemZ/int-div-06.ll new file mode 100644 index 0000000..8576b1b --- /dev/null +++ b/test/CodeGen/SystemZ/int-div-06.ll @@ -0,0 +1,56 @@ +; Test that divisions by constants are implemented as multiplications. +; +; RUN: llc < %s -mtriple=s390x-linux-gnu | FileCheck %s + +; Check signed 32-bit division. +define i32 @f1(i32 %a) { +; CHECK-LABEL: f1: +; CHECK: lgfr [[REG:%r[0-5]]], %r2 +; CHECK: msgfi [[REG]], 502748801 +; CHECK-DAG: srlg [[RES1:%r[0-5]]], [[REG]], 63 +; CHECK-DAG: srag %r2, [[REG]], 46 +; CHECK: ar %r2, [[RES1]] +; CHECK: br %r14 + %b = sdiv i32 %a, 139968 + ret i32 %b +} + +; Check unsigned 32-bit division. +define i32 @f2(i32 %a) { +; CHECK-LABEL: f2: +; CHECK: llgfr [[REG:%r[0-5]]], %r2 +; CHECK: msgfi [[REG]], 502748801 +; CHECK: srlg %r2, [[REG]], 46 +; CHECK: br %r14 + %b = udiv i32 %a, 139968 + ret i32 %b +} + +; Check signed 64-bit division. +define i64 @f3(i64 %dummy, i64 %a) { +; CHECK-LABEL: f3: +; CHECK-DAG: llihf [[CONST:%r[0-5]]], 1005497601 +; CHECK-DAG: oilf [[CONST]], 4251762321 +; CHECK-DAG: srag [[REG:%r[0-5]]], %r3, 63 +; CHECK-DAG: ngr [[REG]], [[CONST]] +; CHECK-DAG: mlgr %r2, [[CONST]] +; CHECK: sgr %r2, [[REG]] +; CHECK: srlg [[RES1:%r[0-5]]], %r2, 63 +; CHECK: srag %r2, %r2, 15 +; CHECK: agr %r2, [[RES1]] +; CHECK: br %r14 + %b = sdiv i64 %a, 139968 + ret i64 %b +} + +; Check unsigned 64-bit division. +define i64 @f4(i64 %dummy, i64 %a) { +; CHECK-LABEL: f4: +; CHECK: llihf [[CONST:%r[0-5]]], 1005497601 +; CHECK: oilf [[CONST]], 4251762321 +; CHECK: mlgr %r2, [[CONST]] +; CHECK: srlg %r2, %r2, 15 +; CHECK: br %r14 + %b = udiv i64 %a, 139968 + ret i64 %b +} diff --git a/test/CodeGen/SystemZ/int-mul-08.ll b/test/CodeGen/SystemZ/int-mul-08.ll index a245760..90b26a4 100644 --- a/test/CodeGen/SystemZ/int-mul-08.ll +++ b/test/CodeGen/SystemZ/int-mul-08.ll @@ -22,9 +22,13 @@ define i64 @f1(i64 %dummy, i64 %a, i64 %b) { ; This needs a rather convoluted sequence. define i64 @f2(i64 %dummy, i64 %a, i64 %b) { ; CHECK-LABEL: f2: -; CHECK: mlgr -; CHECK: agr -; CHECK: agr +; CHECK-DAG: srag [[RES1:%r[0-5]]], %r3, 63 +; CHECK-DAG: srag [[RES2:%r[0-5]]], %r4, 63 +; CHECK-DAG: ngr [[RES1]], %r4 +; CHECK-DAG: ngr [[RES2]], %r3 +; CHECK-DAG: agr [[RES2]], [[RES1]] +; CHECK-DAG: mlgr %r2, %r4 +; CHECK: sgr %r2, [[RES2]] ; CHECK: br %r14 %ax = sext i64 %a to i128 %bx = sext i64 %b to i128 -- cgit v1.1