Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add PUSHPOW2, PUSHPOW2DEC, PUSHNEGPOW2 #176

Open
wants to merge 35 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
35 commits
Select commit Hold shift + click to select a range
d77d2cf
Add PUSHPOW2, PUSHPOW2DEC, PUSHNEGPOW2
Nov 19, 2020
00d5827
Auto update patch version
tonjen Jul 12, 2021
b889846
Auto update patch version
tonjen Jul 21, 2021
ef7ab4b
Auto update patch version
tonjen Jul 22, 2021
e0dc82f
Auto update patch version
tonjen Jul 28, 2021
75a3136
Auto update patch version
tonjen Jul 29, 2021
dcb43f9
Auto update patch version
tonjen Jul 29, 2021
5640cb6
Auto update patch version
tonjen Jul 29, 2021
a96cf90
Auto update patch version
tonjen Jul 30, 2021
f4e0ccc
Auto update patch version
tonjen Jul 30, 2021
de3b0ec
Auto update patch version
tonjen Jul 30, 2021
b113e3e
Auto update patch version
tonjen Jul 30, 2021
e2d835e
Auto update patch version
tonjen Jul 31, 2021
f779bd9
Auto update patch version
tonjen Aug 2, 2021
756ac9e
Auto update patch version
tonjen Aug 2, 2021
70ee03b
Auto update patch version
tonjen Aug 3, 2021
18d197f
Auto update patch version
tonjen Aug 3, 2021
be25b1c
Auto update patch version
tonjen Aug 4, 2021
d2b9f15
Auto update patch version
tonjen Aug 5, 2021
1786428
Auto update patch version
tonjen Aug 6, 2021
7100f78
Auto update patch version
tonjen Aug 7, 2021
97b1384
Auto update patch version
tonjen Aug 11, 2021
251f4dc
Auto update patch version
tonjen Sep 6, 2021
2f9cad9
Auto update patch version
tonjen Sep 24, 2021
c002c6f
Auto update patch version
tonjen Oct 4, 2021
c39fab6
Auto update patch version
tonjen Oct 29, 2021
d470491
Auto update patch version
tonjen Nov 8, 2021
8b992cd
Auto update patch version
tonjen Nov 16, 2021
c99b30d
Auto update patch version
tonjen Dec 6, 2021
ff73f82
Auto update patch version
tonjen Dec 6, 2021
00b7e75
Auto update patch version
tonjen Jan 10, 2022
b346739
Auto update patch version
tonjen Jan 21, 2022
76c775d
Auto update patch version
tonjen Feb 11, 2022
610e7e3
Auto update patch version
tonjen Mar 30, 2022
94cd8db
Update CHANGELOG.md
tonjen Mar 30, 2022
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 10 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
# Changelog

All notable changes to this project will be documented in this file.

## Version: 7.7.34

### New



4 changes: 2 additions & 2 deletions llvm/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -30,10 +30,10 @@ if(NOT DEFINED LLVM_VERSION_MAJOR)
set(LLVM_VERSION_MAJOR 7)
endif()
if(NOT DEFINED LLVM_VERSION_MINOR)
set(LLVM_VERSION_MINOR 0)
set(LLVM_VERSION_MINOR 7)
endif()
if(NOT DEFINED LLVM_VERSION_PATCH)
set(LLVM_VERSION_PATCH 0)
set(LLVM_VERSION_PATCH 34)
endif()
if(NOT DEFINED LLVM_VERSION_SUFFIX)
set(LLVM_VERSION_SUFFIX "")
Expand Down
12 changes: 12 additions & 0 deletions llvm/lib/Target/TVM/TVMInstrInfo.td
Original file line number Diff line number Diff line change
Expand Up @@ -268,6 +268,18 @@ defm CONST_U257 : I<(outs I257:$res), (ins UImm257:$uimm),
(outs), (ins UImm257:$uimm),
[(set I257:$res, (TVMconst_u257 timm:$uimm))],
"PUSHINT\t$res, $uimm", "PUSHINT\t$uimm", 0x82>;
defm CONST_POW2 : I<(outs I257:$res), (ins i257imm:$imm),
(outs), (ins i257imm:$imm),
[(set I257:$res, imm:$imm)],
"PUSHPOW2\t$res, $imm", "PUSHPOW2\t$imm", 0x83>;
defm CONST_POW2DEC : I<(outs I257:$res), (ins i257imm:$imm),
(outs), (ins i257imm:$imm),
[(set I257:$res, imm:$imm)],
"PUSHPOW2DEC\t$res, $imm", "PUSHPOW2DEC\t$imm", 0x84>;
defm CONST_NEGPOW2 : I<(outs I257:$res), (ins i257imm:$imm),
(outs), (ins i257imm:$imm),
[(set I257:$res, imm:$imm)],
"PUSHNEGPOW2\t$res, $imm", "PUSHNEGPOW2\t$imm", 0x85>;
}


Expand Down
41 changes: 41 additions & 0 deletions llvm/lib/Target/TVM/TVMPeephole.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,11 @@ static cl::opt<bool> DisableTVMShorterFormOpt(
"disable-tvm-shorter-form-opt", cl::Hidden,
cl::desc("TVM: Disable shorter form replacement peephole optimizations."),
cl::init(false));
static cl::opt<bool> DisableTVMPushintOpt(
"disable-tvm-pushint-opt", cl::Hidden,
cl::desc("TVM: Disable power of 2 optimizations for constants."),
cl::init(false));

static unsigned BlkPushLimit = 15;
namespace {
class TVMPeephole final : public MachineFunctionPass {
Expand All @@ -64,6 +69,7 @@ class TVMPeephole final : public MachineFunctionPass {
bool runBlkPushCombine(MachineBasicBlock &MBB, const TargetInstrInfo &TII);
bool runReplaceWithShorterForm(MachineBasicBlock &MBB,
const TargetInstrInfo &TII);
bool runPushintOpt(MachineBasicBlock &MBB, const TargetInstrInfo &TII);
bool runMbbInlineOptimization(MachineBasicBlock &MBB,
const TargetInstrInfo &TII);
bool runIfElseOptimization(MachineBasicBlock &MBB,
Expand Down Expand Up @@ -220,6 +226,39 @@ bool TVMPeephole::runReplaceWithShorterForm(MachineBasicBlock &MBB,
return !MIReplace.empty();
}

bool TVMPeephole::runPushintOpt(MachineBasicBlock &MBB,
const TargetInstrInfo &TII) {
std::vector<MachineInstr *> MIRemove;
for (auto &I : MBB) {
if (I.getOpcode() != TVM::CONST_I257_S && I.getOpcode() != TVM::CONST_U257_S)
continue;
APInt Val = I.getOperand(0).getCImm()->getValue();
if (Val.isPowerOf2() && Val.ugt(64)) {
MIRemove.push_back(&I);
BuildMI(&I, TII.get(TVM::CONST_POW2_S))
.addImm(Val.getBitWidth() - Val.countLeadingZeros() - 1);
continue;
}
APInt AbsVal = Val.abs();
if (AbsVal.isPowerOf2() && AbsVal.ugt(64)) {
MIRemove.push_back(&I);
BuildMI(&I, TII.get(TVM::CONST_NEGPOW2_S))
.addImm(AbsVal.getBitWidth() - AbsVal.countLeadingZeros() - 1);
continue;
}
Val += 1;
if (Val.isPowerOf2() && Val.ugt(64)) {
MIRemove.push_back(&I);
BuildMI(&I, TII.get(TVM::CONST_POW2DEC_S))
.addImm(Val.getBitWidth() - Val.countLeadingZeros() - 1);
continue;
}
}
for (auto *I : MIRemove)
I->eraseFromParent();
return !MIRemove.empty();
}

bool TVMPeephole::runImplicitReturnOptimization(MachineBasicBlock &MBB,
const TargetInstrInfo &TII) {
if (MBB.empty())
Expand Down Expand Up @@ -602,6 +641,8 @@ bool TVMPeephole::runOnMachineBasicBlock(MachineBasicBlock &MBB,
Changed |= runBlkPushCombine(MBB, TII);
if (!DisableTVMShorterFormOpt)
Changed |= runReplaceWithShorterForm(MBB, TII);
if (!DisableTVMPushintOpt)
Changed |= runPushintOpt(MBB, TII);

return Changed;
}
Expand Down
4 changes: 2 additions & 2 deletions llvm/test/CodeGen/TVM/frameidx-codegen.ll
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ define i257 @small() {
; CHECK-NEXT: ADDCONST 127
; CHECK-NEXT: GETGLOB 13 CALLX
; CHECK-NEXT: GETGLOB 5
; CHECK-NEXT: PUSHINT 128
; CHECK-NEXT: PUSHPOW2 7
; CHECK-NEXT: ADD
; CHECK-NEXT: SETGLOB 5
entry:
Expand All @@ -45,7 +45,7 @@ define i257 @large() {
; CHECK-NEXT: SUB
; CHECK-NEXT: SETGLOB 5
; CHECK-NEXT: GETGLOB 5
; CHECK-NEXT: PUSHINT 128
; CHECK-NEXT: PUSHPOW2 7
; CHECK-NEXT: ADD
; CHECK-NEXT: GETGLOB 13 CALLX
; CHECK-NEXT: GETGLOB 5
Expand Down
26 changes: 26 additions & 0 deletions llvm/test/CodeGen/TVM/optimizations/pow2.ll
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
; RUN: llc -O3 < %s -march=tvm -filetype=asm | FileCheck %s
target datalayout = "E-S257-i1:257:257-i8:257:257-i16:257:257-i32:257:257-i64:257:257-i257:257:257-p:257:257-a:257:257"
target triple = "tvm"

; CHECK-LABEL: ret1
define i257 @ret1() {
; CHECK: PUSHPOW2 7
ret i257 128
}

; CHECK-LABEL: ret2
define i257 @ret2() {
; CHECK: PUSHNEGPOW2 8
ret i257 -256
}

; CHECK-LABEL: ret3
define i257 @ret3() {
; CHECK: PUSHPOW2DEC 8
ret i257 255
}

; CHECK-LABEL: retneg
define i257 @retneg() {
ret i257 0
}
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ target triple = "tvm"

define i257 @addconst_pos_range_over(i257 %a1) nounwind {
; CHECK-LABEL: addconst_pos_range_over:
; CHECK: PUSHINT
; CHECK: PUSHPOW2
; CHECK-NEXT: ADD
%1 = add i257 128, %a1
ret i257 %1
Expand Down
2 changes: 1 addition & 1 deletion llvm/test/CodeGen/TVM/select-isel.ll
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ target triple = "tvm"
define i257 @foo(i257 %x) {
entry:
; CHECK-LABEL: foo
; CHECK: PUSHINT -0x10000000000000000000000000000000000000000000000000000000000000000
; CHECK: PUSHPOW2
; CHECK-NEXT: EQUAL
; CHECK-NEXT: PUSHINT 7
; CHECK-NEXT: PUSHINT 13
Expand Down