Skip to content

Commit 2011052

Browse files
committed
llvm-reduce: Add pass to reduce MIR instruction flags
1 parent f68c547 commit 2011052

File tree

5 files changed

+116
-1
lines changed

5 files changed

+116
-1
lines changed
Lines changed: 54 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,54 @@
1+
# REQUIRES: amdgpu-registered-target
2+
# RUN: llvm-reduce -simplify-mir -mtriple=amdgcn-amd-amdhsa --test FileCheck --test-arg --check-prefix=CHECK-INTERESTINGNESS --test-arg %s --test-arg --input-file %s -o %t 2> %t.log
3+
# RUN: FileCheck --check-prefix=RESULT %s < %t
4+
5+
# CHECK-INTERESTINGNESS: V_ADD_F32
6+
# CHECK-INTERESTINGNESS: nnan nofpexcept V_MUL_F32
7+
8+
# CHECK-INTERESTINGNESS-COUNT-11: V_MOV_B32
9+
10+
11+
# RESULT: %{{[0-9]+}}:vgpr_32 = V_ADD_F32_e32 %{{[0-9]+}}, %{{[0-9]+}}, implicit $mode, implicit $exec
12+
# RESULT: %{{[0-9]+}}:vgpr_32 = nnan nofpexcept V_MUL_F32_e32 0, %{{[0-9]+}}, implicit $mode, implicit $exec
13+
# RESULT: %{{[0-9]+}}:vgpr_32 = V_MOV_B32_e32
14+
# RESULT: %{{[0-9]+}}:vgpr_32 = V_MOV_B32_e32
15+
# RESULT: %{{[0-9]+}}:vgpr_32 = V_MOV_B32_e32
16+
# RESULT: %{{[0-9]+}}:vgpr_32 = V_MOV_B32_e32
17+
# RESULT: %{{[0-9]+}}:vgpr_32 = V_MOV_B32_e32
18+
# RESULT: %{{[0-9]+}}:vgpr_32 = V_MOV_B32_e32
19+
# RESULT: %{{[0-9]+}}:vgpr_32 = V_MOV_B32_e32
20+
# RESULT: %{{[0-9]+}}:vgpr_32 = V_MOV_B32_e32
21+
# RESULT: %{{[0-9]+}}:vgpr_32 = V_MOV_B32_e32
22+
# RESULT: %{{[0-9]+}}:vgpr_32 = V_MOV_B32_e32
23+
# RESULT: %{{[0-9]+}}:vgpr_32 = V_MOV_B32_e32
24+
25+
---
26+
name: func
27+
tracksRegLiveness: true
28+
body: |
29+
bb.0:
30+
liveins: $vgpr0, $vgpr1
31+
32+
S_WAITCNT 0
33+
%0:vgpr_32 = COPY $vgpr0
34+
%1:vgpr_32 = COPY $vgpr1
35+
%2:vgpr_32 = nofpexcept V_ADD_F32_e32 %0, %1, implicit $mode, implicit $exec
36+
%3:vgpr_32 = nnan nofpexcept V_MUL_F32_e32 0, %2, implicit $mode, implicit $exec
37+
%4:vgpr_32 = nsz V_MUL_F32_e32 0, %3, implicit $mode, implicit $exec
38+
39+
%5:vgpr_32 = nnan V_MOV_B32_e32 0, implicit $exec
40+
%6:vgpr_32 = ninf V_MOV_B32_e32 0, implicit $exec
41+
%7:vgpr_32 = nsz V_MOV_B32_e32 0, implicit $exec
42+
%8:vgpr_32 = arcp V_MOV_B32_e32 0, implicit $exec
43+
%9:vgpr_32 = contract V_MOV_B32_e32 0, implicit $exec
44+
%10:vgpr_32 = afn V_MOV_B32_e32 0, implicit $exec
45+
%11:vgpr_32 = reassoc V_MOV_B32_e32 0, implicit $exec
46+
%12:vgpr_32 = nuw V_MOV_B32_e32 0, implicit $exec
47+
%13:vgpr_32 = nsw V_MOV_B32_e32 0, implicit $exec
48+
%14:vgpr_32 = exact V_MOV_B32_e32 0, implicit $exec
49+
%15:vgpr_32 = nofpexcept V_MOV_B32_e32 0, implicit $exec
50+
S_NOP 0, implicit %3, implicit %4, implicit %5, implicit %6, implicit %7
51+
S_NOP 0, implicit %8, implicit %9, implicit %10, implicit %11, implicit %12
52+
S_ENDPGM 0, implicit %13, implicit %14, implicit %15
53+
...
54+

llvm/tools/llvm-reduce/CMakeLists.txt

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -39,6 +39,7 @@ add_llvm_tool(llvm-reduce
3939
deltas/ReduceOperandsSkip.cpp
4040
deltas/ReduceOperandsToArgs.cpp
4141
deltas/ReduceInstructionsMIR.cpp
42+
deltas/ReduceInstructionFlagsMIR.cpp
4243
deltas/ReduceIRReferences.cpp
4344
llvm-reduce.cpp
4445

llvm/tools/llvm-reduce/DeltaManager.cpp

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,7 @@
2525
#include "deltas/ReduceGlobalVarInitializers.h"
2626
#include "deltas/ReduceGlobalVars.h"
2727
#include "deltas/ReduceIRReferences.h"
28+
#include "deltas/ReduceInstructionFlagsMIR.h"
2829
#include "deltas/ReduceInstructions.h"
2930
#include "deltas/ReduceInstructionsMIR.h"
3031
#include "deltas/ReduceMetadata.h"
@@ -72,7 +73,8 @@ static cl::opt<std::string>
7273
DELTA_PASS("ir-instruction-references", \
7374
reduceIRInstructionReferencesDeltaPass) \
7475
DELTA_PASS("ir-block-references", reduceIRBlockReferencesDeltaPass) \
75-
DELTA_PASS("ir-function-references", reduceIRFunctionReferencesDeltaPass)
76+
DELTA_PASS("ir-function-references", reduceIRFunctionReferencesDeltaPass) \
77+
DELTA_PASS("instruction-flags", reduceInstructionFlagsMIRDeltaPass)
7678

7779
static void runAllDeltaPasses(TestRunner &Tester) {
7880
#define DELTA_PASS(NAME, FUNC) FUNC(Tester);
Lines changed: 35 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,35 @@
1+
//===- ReduceInstructionFlagsMIR.cpp - Specialized Delta Pass -------------===//
2+
//
3+
// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
4+
// See https://llvm.org/LICENSE.txt for license information.
5+
// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
6+
//
7+
//===----------------------------------------------------------------------===//
8+
//
9+
// This file implements a function which calls the Generic Delta pass in order
10+
// to reduce uninteresting MachineInstr flags from the MachineFunction.
11+
//
12+
//===----------------------------------------------------------------------===//
13+
14+
#include "ReduceInstructionFlagsMIR.h"
15+
#include "llvm/CodeGen/MachineFunction.h"
16+
using namespace llvm;
17+
18+
static void removeFlagsFromModule(Oracle &O, ReducerWorkItem &WorkItem) {
19+
for (const Function &F : WorkItem.getModule()) {
20+
if (auto *MF = WorkItem.MMI->getMachineFunction(F)) {
21+
for (MachineBasicBlock &MBB : *MF) {
22+
for (MachineInstr &MI : MBB) {
23+
// TODO: Should this clear flags individually?
24+
if (MI.getFlags() != 0 && !O.shouldKeep())
25+
MI.setFlags(0);
26+
}
27+
}
28+
}
29+
}
30+
}
31+
32+
void llvm::reduceInstructionFlagsMIRDeltaPass(TestRunner &Test) {
33+
outs() << "*** Reducing Instruction flags...\n";
34+
runDeltaPass(Test, removeFlagsFromModule);
35+
}
Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
1+
//===- ReduceInstructionFlagsMIR.h - Specialized Delta Pass --------------===//
2+
//
3+
// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
4+
// See https://llvm.org/LICENSE.txt for license information.
5+
// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
6+
//
7+
//===----------------------------------------------------------------------===//
8+
//
9+
// This file implements a function which calls the Generic Delta pass in order
10+
// to reduce uninteresting MachineInstr flags from the MachineFunction.
11+
//
12+
//===----------------------------------------------------------------------===//
13+
14+
#ifndef LLVM_TOOLS_LLVM_REDUCE_DELTAS_REDUCEINSTRUCTIONFLAGSMIR_H
15+
#define LLVM_TOOLS_LLVM_REDUCE_DELTAS_REDUCEINSTRUCTIONFLAGSMIR_H
16+
17+
#include "Delta.h"
18+
19+
namespace llvm {
20+
void reduceInstructionFlagsMIRDeltaPass(TestRunner &Test);
21+
} // namespace llvm
22+
23+
#endif

0 commit comments

Comments
 (0)