@@ -1272,6 +1272,91 @@ TEST(LoopInfoTest, AuxiliaryIV) {
1272
1272
});
1273
1273
}
1274
1274
1275
+ TEST (LoopInfoTest, LoopNotInSimplifyForm) {
1276
+ const char *ModuleStr =
1277
+ " define void @foo(i32 %n) {\n "
1278
+ " entry:\n "
1279
+ " %guard.cmp = icmp sgt i32 %n, 0\n "
1280
+ " br i1 %guard.cmp, label %for.cond, label %for.end\n "
1281
+ " for.cond:\n "
1282
+ " %i.0 = phi i32 [ 0, %entry ], [ %inc, %latch.1 ], [ %inc, %latch.2 ]\n "
1283
+ " %inc = add nsw i32 %i.0, 1\n "
1284
+ " %cmp = icmp slt i32 %i.0, %n\n "
1285
+ " br i1 %cmp, label %latch.1, label %for.end\n "
1286
+ " latch.1:\n "
1287
+ " br i1 undef, label %for.cond, label %latch.2\n "
1288
+ " latch.2:\n "
1289
+ " br label %for.cond\n "
1290
+ " for.end:\n "
1291
+ " ret void\n "
1292
+ " }\n " ;
1293
+
1294
+ // Parse the module.
1295
+ LLVMContext Context;
1296
+ std::unique_ptr<Module> M = makeLLVMModule (Context, ModuleStr);
1297
+
1298
+ runWithLoopInfo (*M, " foo" , [&](Function &F, LoopInfo &LI) {
1299
+ Function::iterator FI = F.begin ();
1300
+ // First basic block is entry - skip it.
1301
+ BasicBlock *Header = &*(++FI);
1302
+ assert (Header && " No header" );
1303
+ Loop *L = LI.getLoopFor (Header);
1304
+ EXPECT_NE (L, nullptr );
1305
+ EXPECT_FALSE (L->isLoopSimplifyForm ());
1306
+ // No loop guard because loop in not in simplify form.
1307
+ EXPECT_EQ (L->getLoopGuardBranch (), nullptr );
1308
+ EXPECT_FALSE (L->isGuarded ());
1309
+ });
1310
+ }
1311
+
1312
+ TEST (LoopInfoTest, LoopLatchNotExiting) {
1313
+ const char *ModuleStr =
1314
+ " define void @foo(i32* %A, i32 %ub) {\n "
1315
+ " entry:\n "
1316
+ " %guardcmp = icmp slt i32 0, %ub\n "
1317
+ " br i1 %guardcmp, label %for.preheader, label %for.end\n "
1318
+ " for.preheader:\n "
1319
+ " br label %for.body\n "
1320
+ " for.body:\n "
1321
+ " %i = phi i32 [ 0, %for.preheader ], [ %inc, %for.body ]\n "
1322
+ " %idxprom = sext i32 %i to i64\n "
1323
+ " %arrayidx = getelementptr inbounds i32, i32* %A, i64 %idxprom\n "
1324
+ " store i32 %i, i32* %arrayidx, align 4\n "
1325
+ " %inc = add nsw i32 %i, 1\n "
1326
+ " %cmp = icmp slt i32 %inc, %ub\n "
1327
+ " br i1 %cmp, label %for.latch, label %for.exit\n "
1328
+ " for.latch:\n "
1329
+ " br label %for.body\n "
1330
+ " for.exit:\n "
1331
+ " br label %for.end\n "
1332
+ " for.end:\n "
1333
+ " ret void\n "
1334
+ " }\n " ;
1335
+
1336
+ // Parse the module.
1337
+ LLVMContext Context;
1338
+ std::unique_ptr<Module> M = makeLLVMModule (Context, ModuleStr);
1339
+
1340
+ runWithLoopInfoPlus (
1341
+ *M, " foo" ,
1342
+ [&](Function &F, LoopInfo &LI, ScalarEvolution &SE) {
1343
+ Function::iterator FI = F.begin ();
1344
+ // First two basic block are entry and for.preheader - skip them.
1345
+ ++FI;
1346
+ BasicBlock *Header = &*(++FI);
1347
+ BasicBlock *Latch = &*(++FI);
1348
+ assert (Header && " No header" );
1349
+ Loop *L = LI.getLoopFor (Header);
1350
+ EXPECT_NE (L, nullptr );
1351
+ EXPECT_TRUE (L->isLoopSimplifyForm ());
1352
+ EXPECT_EQ (L->getLoopLatch (), Latch);
1353
+ EXPECT_FALSE (L->isLoopExiting (Latch));
1354
+ // No loop guard becuase loop is not exiting on latch.
1355
+ EXPECT_EQ (L->getLoopGuardBranch (), nullptr );
1356
+ EXPECT_FALSE (L->isGuarded ());
1357
+ });
1358
+ }
1359
+
1275
1360
// Examine getUniqueExitBlocks/getUniqueNonLatchExitBlocks functions.
1276
1361
TEST (LoopInfoTest, LoopUniqueExitBlocks) {
1277
1362
const char *ModuleStr =
0 commit comments