blob: f0be9709332bd2a967346776d0d2ed23b0ad17e8 [file] [log] [blame]
Matthias Braun3199c4e2016-05-02 23:05:48 +00001#include "llvm/ADT/STLExtras.h"
Matthias Braunf8422972017-12-13 02:51:04 +00002#include "llvm/CodeGen/LiveIntervals.h"
Matthias Braun3199c4e2016-05-02 23:05:48 +00003#include "llvm/CodeGen/MIRParser/MIRParser.h"
4#include "llvm/CodeGen/MachineFunction.h"
Matthias Braun7938eee2016-05-10 03:03:55 +00005#include "llvm/CodeGen/MachineModuleInfo.h"
David Blaikieb3bde2e2017-11-17 01:07:10 +00006#include "llvm/CodeGen/TargetRegisterInfo.h"
Chandler Carruth9a67b072017-06-06 11:06:56 +00007#include "llvm/IR/LegacyPassManager.h"
Heejin Ahn3306fe12019-11-13 18:19:54 -08008#include "llvm/InitializePasses.h"
Matthias Braun3199c4e2016-05-02 23:05:48 +00009#include "llvm/Support/MemoryBuffer.h"
10#include "llvm/Support/SourceMgr.h"
11#include "llvm/Support/TargetRegistry.h"
12#include "llvm/Support/TargetSelect.h"
13#include "llvm/Target/TargetMachine.h"
14#include "llvm/Target/TargetOptions.h"
Chandler Carruth9a67b072017-06-06 11:06:56 +000015#include "gtest/gtest.h"
NAKAMURA Takumic1857d12016-02-18 07:37:17 +000016
Matthias Braun3199c4e2016-05-02 23:05:48 +000017using namespace llvm;
18
19namespace llvm {
20 void initializeTestPassPass(PassRegistry &);
21}
22
23namespace {
24
25void initLLVM() {
26 InitializeAllTargets();
27 InitializeAllTargetMCs();
28 InitializeAllAsmPrinters();
29 InitializeAllAsmParsers();
30
31 PassRegistry *Registry = PassRegistry::getPassRegistry();
32 initializeCore(*Registry);
33 initializeCodeGen(*Registry);
34}
35
36/// Create a TargetMachine. As we lack a dedicated always available target for
Matthias Braun3865b1d2016-07-26 03:57:45 +000037/// unittests, we go for "AMDGPU" to be able to test normal and subregister
38/// liveranges.
Matthias Braun3d849f62018-11-05 23:49:13 +000039std::unique_ptr<LLVMTargetMachine> createTargetMachine() {
Matthias Braun3865b1d2016-07-26 03:57:45 +000040 Triple TargetTriple("amdgcn--");
Matthias Braun3199c4e2016-05-02 23:05:48 +000041 std::string Error;
42 const Target *T = TargetRegistry::lookupTarget("", TargetTriple, Error);
43 if (!T)
44 return nullptr;
45
46 TargetOptions Options;
Matthias Braun3d849f62018-11-05 23:49:13 +000047 return std::unique_ptr<LLVMTargetMachine>(static_cast<LLVMTargetMachine*>(
48 T->createTargetMachine("AMDGPU", "", "", Options, None, None,
49 CodeGenOpt::Aggressive)));
Matthias Braun3199c4e2016-05-02 23:05:48 +000050}
51
52std::unique_ptr<Module> parseMIR(LLVMContext &Context,
53 legacy::PassManagerBase &PM, std::unique_ptr<MIRParser> &MIR,
Matthias Braun3d849f62018-11-05 23:49:13 +000054 const LLVMTargetMachine &TM, StringRef MIRCode, const char *FuncName) {
Matthias Braun3199c4e2016-05-02 23:05:48 +000055 SMDiagnostic Diagnostic;
56 std::unique_ptr<MemoryBuffer> MBuffer = MemoryBuffer::getMemBuffer(MIRCode);
57 MIR = createMIRParser(std::move(MBuffer), Context);
58 if (!MIR)
59 return nullptr;
60
Matthias Braun7bda1952017-06-06 00:44:35 +000061 std::unique_ptr<Module> M = MIR->parseIRModule();
Matthias Braun3199c4e2016-05-02 23:05:48 +000062 if (!M)
63 return nullptr;
64
65 M->setDataLayout(TM.createDataLayout());
66
Yuanfang Chencc382cf2019-09-30 17:54:50 +000067 MachineModuleInfoWrapperPass *MMIWP = new MachineModuleInfoWrapperPass(&TM);
68 if (MIR->parseMachineFunctions(*M, MMIWP->getMMI()))
Matthias Braun7bda1952017-06-06 00:44:35 +000069 return nullptr;
Yuanfang Chencc382cf2019-09-30 17:54:50 +000070 PM.add(MMIWP);
Matthias Braun3199c4e2016-05-02 23:05:48 +000071
72 return M;
73}
74
75typedef std::function<void(MachineFunction&,LiveIntervals&)> LiveIntervalTest;
76
77struct TestPass : public MachineFunctionPass {
78 static char ID;
79 TestPass() : MachineFunctionPass(ID) {
80 // We should never call this but always use PM.add(new TestPass(...))
81 abort();
82 }
83 TestPass(LiveIntervalTest T) : MachineFunctionPass(ID), T(T) {
84 initializeTestPassPass(*PassRegistry::getPassRegistry());
85 }
86
87 bool runOnMachineFunction(MachineFunction &MF) override {
88 LiveIntervals &LIS = getAnalysis<LiveIntervals>();
89 T(MF, LIS);
90 EXPECT_TRUE(MF.verify(this));
91 return true;
92 }
93
94 void getAnalysisUsage(AnalysisUsage &AU) const override {
95 AU.setPreservesAll();
96 AU.addRequired<LiveIntervals>();
97 AU.addPreserved<LiveIntervals>();
98 MachineFunctionPass::getAnalysisUsage(AU);
99 }
100private:
101 LiveIntervalTest T;
102};
103
Matthias Braun3865b1d2016-07-26 03:57:45 +0000104static MachineInstr &getMI(MachineFunction &MF, unsigned At,
105 unsigned BlockNum) {
106 MachineBasicBlock &MBB = *MF.getBlockNumbered(BlockNum);
107
108 unsigned I = 0;
109 for (MachineInstr &MI : MBB) {
110 if (I == At)
111 return MI;
112 ++I;
113 }
114 llvm_unreachable("Instruction not found");
115}
116
Matthias Braun3199c4e2016-05-02 23:05:48 +0000117/**
118 * Move instruction number \p From in front of instruction number \p To and
119 * update affected liveness intervals with LiveIntervalAnalysis::handleMove().
120 */
121static void testHandleMove(MachineFunction &MF, LiveIntervals &LIS,
Matthias Braunfc4c8a12016-05-24 21:54:01 +0000122 unsigned From, unsigned To, unsigned BlockNum = 0) {
Matthias Braun3865b1d2016-07-26 03:57:45 +0000123 MachineInstr &FromInstr = getMI(MF, From, BlockNum);
124 MachineInstr &ToInstr = getMI(MF, To, BlockNum);
Matthias Braun3199c4e2016-05-02 23:05:48 +0000125
Matthias Braun3865b1d2016-07-26 03:57:45 +0000126 MachineBasicBlock &MBB = *FromInstr.getParent();
127 MBB.splice(ToInstr.getIterator(), &MBB, FromInstr.getIterator());
128 LIS.handleMove(FromInstr, true);
Matthias Braun3199c4e2016-05-02 23:05:48 +0000129}
130
Carl Ritson43e24602020-04-16 19:57:55 +0900131/**
132 * Move instructions numbered \p From inclusive through instruction number
133 * \p To into a newly formed bundle and update affected liveness intervals
134 * with LiveIntervalAnalysis::handleMoveIntoNewBundle().
135 */
136static void testHandleMoveIntoNewBundle(MachineFunction &MF, LiveIntervals &LIS,
137 unsigned From, unsigned To,
138 unsigned BlockNum = 0) {
139 MachineInstr &FromInstr = getMI(MF, From, BlockNum);
140 MachineInstr &ToInstr = getMI(MF, To, BlockNum);
141 MachineBasicBlock &MBB = *FromInstr.getParent();
142 MachineBasicBlock::instr_iterator I = FromInstr.getIterator();
143
144 // Build bundle
145 finalizeBundle(MBB, I, std::next(ToInstr.getIterator()));
146
147 // Update LiveIntervals
148 MachineBasicBlock::instr_iterator BundleStart = std::prev(I);
149 LIS.handleMoveIntoNewBundle(*BundleStart, true);
150}
151
Matthias Braun3199c4e2016-05-02 23:05:48 +0000152static void liveIntervalTest(StringRef MIRFunc, LiveIntervalTest T) {
153 LLVMContext Context;
Matthias Braun3d849f62018-11-05 23:49:13 +0000154 std::unique_ptr<LLVMTargetMachine> TM = createTargetMachine();
Matthias Braun3199c4e2016-05-02 23:05:48 +0000155 // This test is designed for the X86 backend; stop if it is not available.
156 if (!TM)
157 return;
158
159 legacy::PassManager PM;
160
161 SmallString<160> S;
Matthias Braun1cba1402017-02-23 01:09:01 +0000162 StringRef MIRString = (Twine(R"MIR(
163---
164...
165name: func
166registers:
167 - { id: 0, class: sreg_64 }
168body: |
169 bb.0:
170)MIR") + Twine(MIRFunc) + Twine("...\n")).toNullTerminatedStringRef(S);
Matthias Braun3199c4e2016-05-02 23:05:48 +0000171 std::unique_ptr<MIRParser> MIR;
172 std::unique_ptr<Module> M = parseMIR(Context, PM, MIR, *TM, MIRString,
173 "func");
Matthias Braun531f3a92017-06-15 22:50:57 +0000174 ASSERT_TRUE(M);
Matthias Braun3199c4e2016-05-02 23:05:48 +0000175
176 PM.add(new TestPass(T));
177
178 PM.run(*M);
179}
180
181} // End of anonymous namespace.
182
183char TestPass::ID = 0;
184INITIALIZE_PASS(TestPass, "testpass", "testpass", false, false)
185
186TEST(LiveIntervalTest, MoveUpDef) {
187 // Value defined.
Matthias Braun1cba1402017-02-23 01:09:01 +0000188 liveIntervalTest(R"MIR(
189 S_NOP 0
190 S_NOP 0
191 early-clobber %0 = IMPLICIT_DEF
192 S_NOP 0, implicit %0
193)MIR", [](MachineFunction &MF, LiveIntervals &LIS) {
Matthias Braun3199c4e2016-05-02 23:05:48 +0000194 testHandleMove(MF, LIS, 2, 1);
195 });
196}
197
198TEST(LiveIntervalTest, MoveUpRedef) {
Matthias Braun1cba1402017-02-23 01:09:01 +0000199 liveIntervalTest(R"MIR(
200 %0 = IMPLICIT_DEF
201 S_NOP 0
202 %0 = IMPLICIT_DEF implicit %0(tied-def 0)
203 S_NOP 0, implicit %0
204)MIR", [](MachineFunction &MF, LiveIntervals &LIS) {
Matthias Braun3199c4e2016-05-02 23:05:48 +0000205 testHandleMove(MF, LIS, 2, 1);
206 });
207}
208
209TEST(LiveIntervalTest, MoveUpEarlyDef) {
Matthias Braun1cba1402017-02-23 01:09:01 +0000210 liveIntervalTest(R"MIR(
211 S_NOP 0
212 S_NOP 0
213 early-clobber %0 = IMPLICIT_DEF
214 S_NOP 0, implicit %0
215)MIR", [](MachineFunction &MF, LiveIntervals &LIS) {
Matthias Braun3199c4e2016-05-02 23:05:48 +0000216 testHandleMove(MF, LIS, 2, 1);
217 });
218}
219
220TEST(LiveIntervalTest, MoveUpEarlyRedef) {
Matthias Braun1cba1402017-02-23 01:09:01 +0000221 liveIntervalTest(R"MIR(
222 %0 = IMPLICIT_DEF
223 S_NOP 0
224 early-clobber %0 = IMPLICIT_DEF implicit %0(tied-def 0)
225 S_NOP 0, implicit %0
226)MIR", [](MachineFunction &MF, LiveIntervals &LIS) {
Matthias Braun3199c4e2016-05-02 23:05:48 +0000227 testHandleMove(MF, LIS, 2, 1);
228 });
229}
230
231TEST(LiveIntervalTest, MoveUpKill) {
Matthias Braun1cba1402017-02-23 01:09:01 +0000232 liveIntervalTest(R"MIR(
233 %0 = IMPLICIT_DEF
234 S_NOP 0
235 S_NOP 0, implicit %0
236)MIR", [](MachineFunction &MF, LiveIntervals &LIS) {
Matthias Braun3199c4e2016-05-02 23:05:48 +0000237 testHandleMove(MF, LIS, 2, 1);
238 });
239}
240
241TEST(LiveIntervalTest, MoveUpKillFollowing) {
Matthias Braun1cba1402017-02-23 01:09:01 +0000242 liveIntervalTest(R"MIR(
243 %0 = IMPLICIT_DEF
244 S_NOP 0
245 S_NOP 0, implicit %0
246 S_NOP 0, implicit %0
247)MIR", [](MachineFunction &MF, LiveIntervals &LIS) {
Matthias Braun3199c4e2016-05-02 23:05:48 +0000248 testHandleMove(MF, LIS, 2, 1);
249 });
250}
251
252// TODO: Construct a situation where we have intervals following a hole
253// while still having connected components.
254
255TEST(LiveIntervalTest, MoveDownDef) {
256 // Value defined.
Matthias Braun1cba1402017-02-23 01:09:01 +0000257 liveIntervalTest(R"MIR(
258 S_NOP 0
259 early-clobber %0 = IMPLICIT_DEF
260 S_NOP 0
261 S_NOP 0, implicit %0
262)MIR", [](MachineFunction &MF, LiveIntervals &LIS) {
Matthias Braun3199c4e2016-05-02 23:05:48 +0000263 testHandleMove(MF, LIS, 1, 2);
264 });
265}
266
267TEST(LiveIntervalTest, MoveDownRedef) {
Matthias Braun1cba1402017-02-23 01:09:01 +0000268 liveIntervalTest(R"MIR(
269 %0 = IMPLICIT_DEF
270 %0 = IMPLICIT_DEF implicit %0(tied-def 0)
271 S_NOP 0
272 S_NOP 0, implicit %0
273)MIR", [](MachineFunction &MF, LiveIntervals &LIS) {
Matthias Braun3199c4e2016-05-02 23:05:48 +0000274 testHandleMove(MF, LIS, 1, 2);
275 });
276}
277
278TEST(LiveIntervalTest, MoveDownEarlyDef) {
Matthias Braun1cba1402017-02-23 01:09:01 +0000279 liveIntervalTest(R"MIR(
280 S_NOP 0
281 early-clobber %0 = IMPLICIT_DEF
282 S_NOP 0
283 S_NOP 0, implicit %0
284)MIR", [](MachineFunction &MF, LiveIntervals &LIS) {
Matthias Braun3199c4e2016-05-02 23:05:48 +0000285 testHandleMove(MF, LIS, 1, 2);
286 });
287}
288
289TEST(LiveIntervalTest, MoveDownEarlyRedef) {
Matthias Braun1cba1402017-02-23 01:09:01 +0000290 liveIntervalTest(R"MIR(
291 %0 = IMPLICIT_DEF
292 early-clobber %0 = IMPLICIT_DEF implicit %0(tied-def 0)
293 S_NOP 0
294 S_NOP 0, implicit %0
295)MIR", [](MachineFunction &MF, LiveIntervals &LIS) {
Matthias Braun3199c4e2016-05-02 23:05:48 +0000296 testHandleMove(MF, LIS, 1, 2);
297 });
298}
299
300TEST(LiveIntervalTest, MoveDownKill) {
Matthias Braun1cba1402017-02-23 01:09:01 +0000301 liveIntervalTest(R"MIR(
302 %0 = IMPLICIT_DEF
303 S_NOP 0, implicit %0
304 S_NOP 0
305)MIR", [](MachineFunction &MF, LiveIntervals &LIS) {
Matthias Braun3199c4e2016-05-02 23:05:48 +0000306 testHandleMove(MF, LIS, 1, 2);
307 });
308}
309
310TEST(LiveIntervalTest, MoveDownKillFollowing) {
Matthias Braun1cba1402017-02-23 01:09:01 +0000311 liveIntervalTest(R"MIR(
312 %0 = IMPLICIT_DEF
313 S_NOP 0
314 S_NOP 0, implicit %0
315 S_NOP 0, implicit %0
316)MIR", [](MachineFunction &MF, LiveIntervals &LIS) {
Matthias Braun3199c4e2016-05-02 23:05:48 +0000317 testHandleMove(MF, LIS, 1, 2);
318 });
319}
320
Matthias Braun71474e82016-05-06 21:47:41 +0000321TEST(LiveIntervalTest, MoveUndefUse) {
Matthias Braun1cba1402017-02-23 01:09:01 +0000322 liveIntervalTest(R"MIR(
323 %0 = IMPLICIT_DEF
324 S_NOP 0, implicit undef %0
325 S_NOP 0, implicit %0
326 S_NOP 0
327)MIR", [](MachineFunction &MF, LiveIntervals &LIS) {
Matthias Braun71474e82016-05-06 21:47:41 +0000328 testHandleMove(MF, LIS, 1, 3);
329 });
330}
331
Matthias Braunfc4c8a12016-05-24 21:54:01 +0000332TEST(LiveIntervalTest, MoveUpValNos) {
333 // handleMoveUp() had a bug where it would reuse the value number of the
Matt Arsenaultdf3af002019-09-26 15:20:16 +0000334 // destination segment, even though we have no guarantee that this valno
335 // wasn't used in other segments.
Matthias Braun1cba1402017-02-23 01:09:01 +0000336 liveIntervalTest(R"MIR(
337 successors: %bb.1, %bb.2
338 %0 = IMPLICIT_DEF
Puyan Lotfi43e94b12018-01-31 22:04:26 +0000339 S_CBRANCH_VCCNZ %bb.2, implicit undef $vcc
Matthias Braun1cba1402017-02-23 01:09:01 +0000340 S_BRANCH %bb.1
341 bb.2:
342 S_NOP 0, implicit %0
343 bb.1:
344 successors: %bb.2
345 %0 = IMPLICIT_DEF implicit %0(tied-def 0)
346 %0 = IMPLICIT_DEF implicit %0(tied-def 0)
347 %0 = IMPLICIT_DEF implicit %0(tied-def 0)
348 S_BRANCH %bb.2
349)MIR", [](MachineFunction &MF, LiveIntervals &LIS) {
Matthias Braunfc4c8a12016-05-24 21:54:01 +0000350 testHandleMove(MF, LIS, 2, 0, 2);
351 });
352}
353
Matthias Braun959a8c92016-06-11 00:31:28 +0000354TEST(LiveIntervalTest, MoveOverUndefUse0) {
355 // findLastUseBefore() used by handleMoveUp() must ignore undef operands.
Matthias Braun1cba1402017-02-23 01:09:01 +0000356 liveIntervalTest(R"MIR(
357 %0 = IMPLICIT_DEF
358 S_NOP 0
359 S_NOP 0, implicit undef %0
360 %0 = IMPLICIT_DEF implicit %0(tied-def 0)
361)MIR", [](MachineFunction &MF, LiveIntervals &LIS) {
Matthias Braun959a8c92016-06-11 00:31:28 +0000362 testHandleMove(MF, LIS, 3, 1);
363 });
364}
365
366TEST(LiveIntervalTest, MoveOverUndefUse1) {
367 // findLastUseBefore() used by handleMoveUp() must ignore undef operands.
Matthias Braun1cba1402017-02-23 01:09:01 +0000368 liveIntervalTest(R"MIR(
Puyan Lotfi43e94b12018-01-31 22:04:26 +0000369 $sgpr0 = IMPLICIT_DEF
Matthias Braun1cba1402017-02-23 01:09:01 +0000370 S_NOP 0
Puyan Lotfi43e94b12018-01-31 22:04:26 +0000371 S_NOP 0, implicit undef $sgpr0
372 $sgpr0 = IMPLICIT_DEF implicit $sgpr0(tied-def 0)
Matthias Braun1cba1402017-02-23 01:09:01 +0000373)MIR", [](MachineFunction &MF, LiveIntervals &LIS) {
Matthias Braun959a8c92016-06-11 00:31:28 +0000374 testHandleMove(MF, LIS, 3, 1);
375 });
376}
377
Matthias Braun3865b1d2016-07-26 03:57:45 +0000378TEST(LiveIntervalTest, SubRegMoveDown) {
379 // Subregister ranges can have holes inside a basic block. Check for a
380 // movement of the form 32->150 in a liverange [16, 32) [100,200).
Matthias Braun1cba1402017-02-23 01:09:01 +0000381 liveIntervalTest(R"MIR(
382 successors: %bb.1, %bb.2
383 %0 = IMPLICIT_DEF
Puyan Lotfi43e94b12018-01-31 22:04:26 +0000384 S_CBRANCH_VCCNZ %bb.2, implicit undef $vcc
Matthias Braun1cba1402017-02-23 01:09:01 +0000385 S_BRANCH %bb.1
386 bb.2:
387 successors: %bb.1
388 S_NOP 0, implicit %0.sub0
389 S_NOP 0, implicit %0.sub1
390 S_NOP 0
391 undef %0.sub0 = IMPLICIT_DEF
392 %0.sub1 = IMPLICIT_DEF
393 bb.1:
394 S_NOP 0, implicit %0
395)MIR", [](MachineFunction &MF, LiveIntervals &LIS) {
Matthias Braun3865b1d2016-07-26 03:57:45 +0000396 // Scheduler behaviour: Clear def,read-undef flag and move.
397 MachineInstr &MI = getMI(MF, 3, /*BlockNum=*/1);
398 MI.getOperand(0).setIsUndef(false);
399 testHandleMove(MF, LIS, 1, 4, /*BlockNum=*/1);
400 });
401}
402
Stanislav Mekhanoshinb546174b2017-03-11 00:14:52 +0000403TEST(LiveIntervalTest, SubRegMoveUp) {
404 // handleMoveUp had a bug not updating valno of segment incoming to bb.2
405 // after swapping subreg definitions.
406 liveIntervalTest(R"MIR(
407 successors: %bb.1, %bb.2
408 undef %0.sub0 = IMPLICIT_DEF
409 %0.sub1 = IMPLICIT_DEF
Puyan Lotfi43e94b12018-01-31 22:04:26 +0000410 S_CBRANCH_VCCNZ %bb.2, implicit undef $vcc
Stanislav Mekhanoshinb546174b2017-03-11 00:14:52 +0000411 S_BRANCH %bb.1
412 bb.1:
413 S_NOP 0, implicit %0.sub1
414 bb.2:
415 S_NOP 0, implicit %0.sub1
416)MIR", [](MachineFunction &MF, LiveIntervals &LIS) {
417 testHandleMove(MF, LIS, 1, 0);
418 });
419}
420
Tim Renouff40707a2018-02-26 14:42:13 +0000421TEST(LiveIntervalTest, DeadSubRegMoveUp) {
422 // handleMoveUp had a bug where moving a dead subreg def into the middle of
423 // an earlier segment resulted in an invalid live range.
424 liveIntervalTest(R"MIR(
425 undef %125.sub0:vreg_128 = V_MOV_B32_e32 0, implicit $exec
426 %125.sub1:vreg_128 = COPY %125.sub0
427 %125.sub2:vreg_128 = COPY %125.sub0
428 undef %51.sub0:vreg_128 = V_MOV_B32_e32 898625526, implicit $exec
429 %51.sub1:vreg_128 = COPY %51.sub0
430 %51.sub2:vreg_128 = COPY %51.sub0
431 %52:vgpr_32 = V_MOV_B32_e32 986714345, implicit $exec
432 %54:vgpr_32 = V_MOV_B32_e32 1742342378, implicit $exec
433 %57:vgpr_32 = V_MOV_B32_e32 3168768712, implicit $exec
434 %59:vgpr_32 = V_MOV_B32_e32 1039972644, implicit $exec
435 %60:vgpr_32 = V_MAD_F32 0, %52, 0, undef %61:vgpr_32, 0, %59, 0, 0, implicit $exec
436 %63:vgpr_32 = V_ADD_F32_e32 %51.sub3, undef %64:vgpr_32, implicit $exec
437 dead %66:vgpr_32 = V_MAD_F32 0, %60, 0, undef %67:vgpr_32, 0, %125.sub2, 0, 0, implicit $exec
438 undef %124.sub1:vreg_128 = V_MAD_F32 0, %57, 0, undef %70:vgpr_32, 0, %125.sub1, 0, 0, implicit $exec
439 %124.sub0:vreg_128 = V_MAD_F32 0, %54, 0, undef %73:vgpr_32, 0, %125.sub0, 0, 0, implicit $exec
440 dead undef %125.sub3:vreg_128 = V_MAC_F32_e32 %63, undef %76:vgpr_32, %125.sub3, implicit $exec
441)MIR", [](MachineFunction &MF, LiveIntervals &LIS) {
442 testHandleMove(MF, LIS, 15, 12);
443 });
444}
445
Matt Arsenaultd4274f02019-10-18 23:24:25 +0000446TEST(LiveIntervalTest, TestMoveSubRegDefAcrossUseDef) {
447 liveIntervalTest(R"MIR(
448 %1:vreg_64 = IMPLICIT_DEF
449
450 bb.1:
451 %2:vgpr_32 = V_MOV_B32_e32 2, implicit $exec
452 %3:vgpr_32 = V_ADD_U32_e32 %2, %1.sub0, implicit $exec
453 undef %1.sub0:vreg_64 = V_ADD_U32_e32 %2, %2, implicit $exec
454 %1.sub1:vreg_64 = COPY %2
455 S_NOP 0, implicit %1.sub1
456 S_BRANCH %bb.1
457
458)MIR", [](MachineFunction &MF, LiveIntervals &LIS) {
459 MachineInstr &UndefSubregDef = getMI(MF, 2, 1);
460 // The scheduler clears undef from subregister defs before moving
461 UndefSubregDef.getOperand(0).setIsUndef(false);
462 testHandleMove(MF, LIS, 3, 1, 1);
463 });
464}
465
466TEST(LiveIntervalTest, TestMoveSubRegDefAcrossUseDefMulti) {
467 liveIntervalTest(R"MIR(
468 %1:vreg_96 = IMPLICIT_DEF
469
470 bb.1:
471 %2:vgpr_32 = V_MOV_B32_e32 2, implicit $exec
472 %3:vgpr_32 = V_ADD_U32_e32 %2, %1.sub0, implicit $exec
473 undef %1.sub0:vreg_96 = V_ADD_U32_e32 %2, %2, implicit $exec
474 %1.sub1:vreg_96 = COPY %2
475 %1.sub2:vreg_96 = COPY %2
476 S_NOP 0, implicit %1.sub1, implicit %1.sub2
477 S_BRANCH %bb.1
478
479)MIR", [](MachineFunction &MF, LiveIntervals &LIS) {
480 MachineInstr &UndefSubregDef = getMI(MF, 2, 1);
481 // The scheduler clears undef from subregister defs before moving
482 UndefSubregDef.getOperand(0).setIsUndef(false);
483 testHandleMove(MF, LIS, 4, 1, 1);
484 });
485}
Carl Ritson43e24602020-04-16 19:57:55 +0900486
487TEST(LiveIntervalTest, BundleUse) {
488 liveIntervalTest(R"MIR(
489 %0 = IMPLICIT_DEF
490 S_NOP 0
491 S_NOP 0, implicit %0
492 S_NOP 0
493)MIR", [](MachineFunction &MF, LiveIntervals &LIS) {
494 testHandleMoveIntoNewBundle(MF, LIS, 1, 2);
495 });
496}
497
498TEST(LiveIntervalTest, BundleDef) {
499 liveIntervalTest(R"MIR(
500 %0 = IMPLICIT_DEF
501 S_NOP 0
502 S_NOP 0, implicit %0
503 S_NOP 0
504)MIR", [](MachineFunction &MF, LiveIntervals &LIS) {
505 testHandleMoveIntoNewBundle(MF, LIS, 0, 1);
506 });
507}
508
509TEST(LiveIntervalTest, BundleRedef) {
510 liveIntervalTest(R"MIR(
511 %0 = IMPLICIT_DEF
512 S_NOP 0
513 %0 = IMPLICIT_DEF implicit %0(tied-def 0)
514 S_NOP 0, implicit %0
515)MIR", [](MachineFunction &MF, LiveIntervals &LIS) {
516 testHandleMoveIntoNewBundle(MF, LIS, 1, 2);
517 });
518}
519
520TEST(LiveIntervalTest, BundleInternalUse) {
521 liveIntervalTest(R"MIR(
522 %0 = IMPLICIT_DEF
523 S_NOP 0
524 S_NOP 0, implicit %0
525 S_NOP 0
526)MIR", [](MachineFunction &MF, LiveIntervals &LIS) {
527 testHandleMoveIntoNewBundle(MF, LIS, 0, 2);
528 });
529}
530
531TEST(LiveIntervalTest, BundleUndefUse) {
532 liveIntervalTest(R"MIR(
533 %0 = IMPLICIT_DEF
534 S_NOP 0
535 S_NOP 0, implicit undef %0
536 S_NOP 0
537)MIR", [](MachineFunction &MF, LiveIntervals &LIS) {
538 testHandleMoveIntoNewBundle(MF, LIS, 1, 2);
539 });
540}
541
542TEST(LiveIntervalTest, BundleSubRegUse) {
543 liveIntervalTest(R"MIR(
544 successors: %bb.1, %bb.2
545 undef %0.sub0 = IMPLICIT_DEF
546 %0.sub1 = IMPLICIT_DEF
547 S_CBRANCH_VCCNZ %bb.2, implicit undef $vcc
548 S_BRANCH %bb.1
549 bb.1:
550 S_NOP 0
551 S_NOP 0, implicit %0.sub1
552 bb.2:
553 S_NOP 0, implicit %0.sub1
554)MIR", [](MachineFunction &MF, LiveIntervals &LIS) {
555 testHandleMoveIntoNewBundle(MF, LIS, 0, 1, 1);
556 });
557}
558
559TEST(LiveIntervalTest, BundleSubRegDef) {
560 liveIntervalTest(R"MIR(
561 successors: %bb.1, %bb.2
562 undef %0.sub0 = IMPLICIT_DEF
563 %0.sub1 = IMPLICIT_DEF
564 S_CBRANCH_VCCNZ %bb.2, implicit undef $vcc
565 S_BRANCH %bb.1
566 bb.1:
567 S_NOP 0
568 S_NOP 0, implicit %0.sub1
569 bb.2:
570 S_NOP 0, implicit %0.sub1
571)MIR", [](MachineFunction &MF, LiveIntervals &LIS) {
572 testHandleMoveIntoNewBundle(MF, LIS, 0, 1, 0);
573 });
574}
575
Matthias Braun3199c4e2016-05-02 23:05:48 +0000576int main(int argc, char **argv) {
577 ::testing::InitGoogleTest(&argc, argv);
578 initLLVM();
579 return RUN_ALL_TESTS();
NAKAMURA Takumic1857d12016-02-18 07:37:17 +0000580}