diff options
author | Brian Gesiak <modocache@gmail.com> | 2018-04-12 21:28:04 +0000 |
---|---|---|
committer | Brian Gesiak <modocache@gmail.com> | 2018-04-12 21:28:04 +0000 |
commit | d0d2ce942507daf7d3315ef5e070e89f2823f1ef (patch) | |
tree | d56052f4e7c668bfab617dbed06d0f127fb3de59 /llvm | |
parent | 00db326b0d5fdd10998fe070fdaf80d3cc731585 (diff) | |
download | bcm5719-llvm-d0d2ce942507daf7d3315ef5e070e89f2823f1ef.tar.gz bcm5719-llvm-d0d2ce942507daf7d3315ef5e070e89f2823f1ef.zip |
Let llvm-diff correctly deal with Undef/ConstantAggregateZero/ConstantVector/IndirectBr
Summary:
llvm-diff incorrectly reports that there's a diff when input IR contains undef/zeroinitializer/constantvector/indirectbr.
(This happens even if two identical files are given, e.g. `llvm-diff x.ll x.ll`)
This is fix to the bug report https://bugs.llvm.org/show_bug.cgi?id=33623 .
Reviewers: dexonsmith, rjmccall
Reviewed By: rjmccall
Subscribers: chenwj, mgrang, llvm-commits
Differential Revision: https://reviews.llvm.org/D34856
llvm-svn: 329957
Diffstat (limited to 'llvm')
-rw-r--r-- | llvm/test/tools/llvm-diff/constantvector.ll | 16 | ||||
-rw-r--r-- | llvm/test/tools/llvm-diff/indirectbr.ll | 11 | ||||
-rw-r--r-- | llvm/test/tools/llvm-diff/undef.ll | 11 | ||||
-rw-r--r-- | llvm/test/tools/llvm-diff/zeroinitializer.bc.ll | 11 | ||||
-rw-r--r-- | llvm/tools/llvm-diff/DifferenceEngine.cpp | 37 |
5 files changed, 84 insertions, 2 deletions
diff --git a/llvm/test/tools/llvm-diff/constantvector.ll b/llvm/test/tools/llvm-diff/constantvector.ll new file mode 100644 index 00000000000..96bb304eccf --- /dev/null +++ b/llvm/test/tools/llvm-diff/constantvector.ll @@ -0,0 +1,16 @@ +; Bugzilla: https://bugs.llvm.org/show_bug.cgi?id=33623 +; RUN: llvm-diff %s %s + +%struct.it = type { i64, i64* } + +@a_vector = internal global [2 x i64] zeroinitializer, align 16 + +define i32 @foo(%struct.it* %it) { + +entry: + %a = getelementptr inbounds %struct.it, %struct.it* %it, i64 0, i32 1 + %tmp0 = bitcast i64** %a to <2 x i64*>* + store <2 x i64*> <i64* getelementptr inbounds ([2 x i64], [2 x i64]* @a_vector, i64 0, i64 0), i64* getelementptr inbounds ([2 x i64], [2 x i64]* @a_vector, i64 0, i64 0)>, <2 x i64*>* %tmp0, align 8 + + ret i32 0 +} diff --git a/llvm/test/tools/llvm-diff/indirectbr.ll b/llvm/test/tools/llvm-diff/indirectbr.ll new file mode 100644 index 00000000000..cff43fc7eb1 --- /dev/null +++ b/llvm/test/tools/llvm-diff/indirectbr.ll @@ -0,0 +1,11 @@ +; Bugzilla: https://bugs.llvm.org/show_bug.cgi?id=33623 +; RUN: llvm-diff %s %s + +define i32 @foo(i8*) { +entry: + indirectbr i8* %0, [label %A, label %B, label %entry] +A: + ret i32 1 +B: + ret i32 2 +} diff --git a/llvm/test/tools/llvm-diff/undef.ll b/llvm/test/tools/llvm-diff/undef.ll new file mode 100644 index 00000000000..607fb1f425e --- /dev/null +++ b/llvm/test/tools/llvm-diff/undef.ll @@ -0,0 +1,11 @@ +; Bugzilla: https://bugs.llvm.org/show_bug.cgi?id=33623 +; RUN: llvm-diff %s %s + +%A = type { i64, i64 } +@_gm_ = global <2 x %A*> zeroinitializer + +define void @f() { +entry: + store <2 x %A*> undef, <2 x %A*>* @_gm_ + ret void +} diff --git a/llvm/test/tools/llvm-diff/zeroinitializer.bc.ll b/llvm/test/tools/llvm-diff/zeroinitializer.bc.ll new file mode 100644 index 00000000000..a6dece35cdc --- /dev/null +++ b/llvm/test/tools/llvm-diff/zeroinitializer.bc.ll @@ -0,0 +1,11 @@ +; Bugzilla: https://bugs.llvm.org/show_bug.cgi?id=33623 +; RUN: llvm-diff %s %s + +%A = type { i64, i64 } +@_gm_ = global <2 x %A*> zeroinitializer + +define void @f() { +entry: + store <2 x %A*> zeroinitializer, <2 x %A*>* @_gm_ + ret void +} diff --git a/llvm/tools/llvm-diff/DifferenceEngine.cpp b/llvm/tools/llvm-diff/DifferenceEngine.cpp index 95a63d7f9c8..af0a055ea21 100644 --- a/llvm/tools/llvm-diff/DifferenceEngine.cpp +++ b/llvm/tools/llvm-diff/DifferenceEngine.cpp @@ -303,6 +303,26 @@ class FunctionDifferenceEngine { if (TryUnify) tryUnify(LI->getSuccessor(0), RI->getSuccessor(0)); return false; + } else if (isa<IndirectBrInst>(L)) { + IndirectBrInst *LI = cast<IndirectBrInst>(L); + IndirectBrInst *RI = cast<IndirectBrInst>(R); + if (LI->getNumDestinations() != RI->getNumDestinations()) { + if (Complain) Engine.log("indirectbr # of destinations differ"); + return true; + } + + if (!equivalentAsOperands(LI->getAddress(), RI->getAddress())) { + if (Complain) Engine.log("indirectbr addresses differ"); + return true; + } + + if (TryUnify) { + for (unsigned i = 0; i < LI->getNumDestinations(); i++) { + tryUnify(LI->getDestination(i), RI->getDestination(i)); + } + } + return false; + } else if (isa<SwitchInst>(L)) { SwitchInst *LI = cast<SwitchInst>(L); SwitchInst *RI = cast<SwitchInst>(R); @@ -377,9 +397,9 @@ class FunctionDifferenceEngine { return equivalentAsOperands(cast<ConstantExpr>(L), cast<ConstantExpr>(R)); - // Nulls of the "same type" don't always actually have the same + // Constants of the "same type" don't always actually have the same // type; I don't know why. Just white-list them. - if (isa<ConstantPointerNull>(L)) + if (isa<ConstantPointerNull>(L) || isa<UndefValue>(L) || isa<ConstantAggregateZero>(L)) return true; // Block addresses only match if we've already encountered the @@ -388,6 +408,19 @@ class FunctionDifferenceEngine { return Blocks[cast<BlockAddress>(L)->getBasicBlock()] == cast<BlockAddress>(R)->getBasicBlock(); + // If L and R are ConstantVectors, compare each element + if (isa<ConstantVector>(L)) { + ConstantVector *CVL = cast<ConstantVector>(L); + ConstantVector *CVR = cast<ConstantVector>(R); + if (CVL->getType()->getNumElements() != CVR->getType()->getNumElements()) + return false; + for (unsigned i = 0; i < CVL->getType()->getNumElements(); i++) { + if (!equivalentAsOperands(CVL->getOperand(i), CVR->getOperand(i))) + return false; + } + return true; + } + return false; } |