llvm.org GIT mirror llvm / e8a290f
Reapply r68211, with the miscompilations it caused fixed. git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@68262 91177308-0d34-0410-b5e6-96231b3b80d8 Owen Anderson 10 years ago
2 changed file(s) with 82 addition(s) and 9 deletion(s). Raw diff Collapse all Expand all
12931293 uint32_t nextNum = VN.getNextUnusedValueNumber();
12941294 unsigned num = VN.lookup_or_add(I);
12951295
1296 if (BranchInst* BI = dyn_cast(I)) {
1297 localAvail[I->getParent()]->table.insert(std::make_pair(num, I));
1298
1299 if (!BI->isConditional() || isa(BI->getCondition()))
1300 return false;
1301
1302 Value* branchCond = BI->getCondition();
1303 uint32_t condVN = VN.lookup_or_add(branchCond);
1304
1305 BasicBlock* trueSucc = BI->getSuccessor(0);
1306 BasicBlock* falseSucc = BI->getSuccessor(1);
1307
1308 if (trueSucc->getSinglePredecessor())
1309 localAvail[trueSucc]->table[condVN] = ConstantInt::getTrue();
1310 if (falseSucc->getSinglePredecessor())
1311 localAvail[falseSucc]->table[condVN] = ConstantInt::getFalse();
1312
1313 return false;
1314
12961315 // Allocations are always uniquely numbered, so we can save time and memory
1297 // by fast failing them.
1298 if (isa(I) || isa(I)) {
1316 // by fast failing them.
1317 } else if (isa(I) || isa(I)) {
12991318 localAvail[I->getParent()]->table.insert(std::make_pair(num, I));
13001319 return false;
13011320 }
14041423
14051424
14061425 bool GVN::processBlock(BasicBlock* BB) {
1407 DomTreeNode* DTN = DT->getNode(BB);
14081426 // FIXME: Kill off toErase by doing erasing eagerly in a helper function (and
14091427 // incrementing BI before processing an instruction).
14101428 SmallVector toErase;
14111429 bool changed_function = false;
1412
1413 if (DTN->getIDom())
1414 localAvail[BB] =
1415 new ValueNumberScope(localAvail[DTN->getIDom()->getBlock()]);
1416 else
1417 localAvail[BB] = new ValueNumberScope(0);
14181430
14191431 for (BasicBlock::iterator BI = BB->begin(), BE = BB->end();
14201432 BI != BE;) {
16061618 bool GVN::iterateOnFunction(Function &F) {
16071619 cleanupGlobalSets();
16081620
1621 for (df_iterator DI = df_begin(DT->getRootNode()),
1622 DE = df_end(DT->getRootNode()); DI != DE; ++DI) {
1623 if (DI->getIDom())
1624 localAvail[DI->getBlock()] =
1625 new ValueNumberScope(localAvail[DI->getIDom()->getBlock()]);
1626 else
1627 localAvail[DI->getBlock()] = new ValueNumberScope(0);
1628 }
1629
16091630 // Top-down walk of the dominator tree
16101631 bool changed = false;
16111632 #if 0
0 ; RUN: llvm-as < %s | opt -gvn | llvm-dis | grep {br i1 false}
1
2 @a = external global i32 ; [#uses=7]
3
4 define i32 @foo() nounwind {
5 entry:
6 %0 = load i32* @a, align 4 ; [#uses=1]
7 %1 = icmp eq i32 %0, 4 ; [#uses=1]
8 br i1 %1, label %bb, label %bb1
9
10 bb: ; preds = %entry
11 br label %bb8
12
13 bb1: ; preds = %entry
14 %2 = load i32* @a, align 4 ; [#uses=1]
15 %3 = icmp eq i32 %2, 5 ; [#uses=1]
16 br i1 %3, label %bb2, label %bb3
17
18 bb2: ; preds = %bb1
19 br label %bb8
20
21 bb3: ; preds = %bb1
22 %4 = load i32* @a, align 4 ; [#uses=1]
23 %5 = icmp eq i32 %4, 4 ; [#uses=1]
24 br i1 %5, label %bb4, label %bb5
25
26 bb4: ; preds = %bb3
27 %6 = load i32* @a, align 4 ; [#uses=1]
28 %7 = add i32 %6, 5 ; [#uses=1]
29 br label %bb8
30
31 bb5: ; preds = %bb3
32 %8 = load i32* @a, align 4 ; [#uses=1]
33 %9 = icmp eq i32 %8, 5 ; [#uses=1]
34 br i1 %9, label %bb6, label %bb7
35
36 bb6: ; preds = %bb5
37 %10 = load i32* @a, align 4 ; [#uses=1]
38 %11 = add i32 %10, 4 ; [#uses=1]
39 br label %bb8
40
41 bb7: ; preds = %bb5
42 %12 = load i32* @a, align 4 ; [#uses=1]
43 br label %bb8
44
45 bb8: ; preds = %bb7, %bb6, %bb4, %bb2, %bb
46 %.0 = phi i32 [ %12, %bb7 ], [ %11, %bb6 ], [ %7, %bb4 ], [ 4, %bb2 ], [ 5, %bb ] ; [#uses=1]
47 br label %return
48
49 return: ; preds = %bb8
50 ret i32 %.0
51 }