[PATCH] D104734: [llvm-diff] Explicitly check ConstantStructs for differences
Bill Wendling via Phabricator via llvm-commits
llvm-commits at lists.llvm.org
Tue Jun 22 11:49:56 PDT 2021
void created this revision.
void added reviewers: rjmccall, dexonsmith, arsenm.
void requested review of this revision.
Herald added subscribers: llvm-commits, wdng.
Herald added a project: LLVM.
A ConstantStruct is renamed when the LLVM context sees a new one. This
makes global variable initializers appear different when they aren't.
Instead, check the ConstantStruct for equivalence.
Repository:
rG LLVM Github Monorepo
https://reviews.llvm.org/D104734
Files:
llvm/test/tools/llvm-diff/initializers.ll
llvm/tools/llvm-diff/DifferenceEngine.cpp
Index: llvm/tools/llvm-diff/DifferenceEngine.cpp
===================================================================
--- llvm/tools/llvm-diff/DifferenceEngine.cpp
+++ llvm/tools/llvm-diff/DifferenceEngine.cpp
@@ -404,6 +404,9 @@
return false;
}
+private:
+ std::vector<StringRef> StructStack;
+
public:
bool equivalentAsOperands(const Constant *L, const Constant *R) {
// Use equality as a preliminary filter.
@@ -465,6 +468,34 @@
return true;
}
+ // If L and R are ConstantStructs, compare each field and type.
+ if (isa<ConstantStruct>(L)) {
+ const ConstantStruct *CSL = cast<ConstantStruct>(L);
+ const ConstantStruct *CSR = cast<ConstantStruct>(R);
+
+ if (CSL->getType()->getNumElements() != CSR->getType()->getNumElements())
+ return false;
+
+ StructStack.push_back(CSL->getName());
+
+ for (unsigned I = 0; I < CSL->getType()->getNumElements(); I++) {
+ const Value *LAgg = CSL->getAggregateElement(I);
+ const Value *RAgg = CSR->getAggregateElement(I);
+
+ if (std::find(StructStack.begin(), StructStack.end(),
+ LAgg->getName()) != StructStack.end())
+ continue;
+
+ if (!equivalentAsOperands(LAgg, RAgg)) {
+ StructStack.pop_back();
+ return false;
+ }
+ }
+
+ StructStack.pop_back();
+ return true;
+ }
+
return false;
}
Index: llvm/test/tools/llvm-diff/initializers.ll
===================================================================
--- llvm/test/tools/llvm-diff/initializers.ll
+++ llvm/test/tools/llvm-diff/initializers.ll
@@ -10,3 +10,16 @@
%1 = getelementptr [2 x i16*], [2 x i16*]* @gv2, i64 0, i64 undef
ret void
}
+
+; A named structure may be renamed when the right module is read. This is due
+; to the LLParser being different between the left and right modules, and the
+; context renaming one.
+
+%struct.ty1 = type { i16, i16 }
+
+ at gv3 = internal global [1 x %struct.ty1] [%struct.ty1 { i16 928, i16 0 }], align 16
+
+define void @bar() {
+ %1 = getelementptr [1 x %struct.ty1], [1 x %struct.ty1]* @gv3, i64 0, i64 undef
+ ret void
+}
-------------- next part --------------
A non-text attachment was scrubbed...
Name: D104734.353738.patch
Type: text/x-patch
Size: 2158 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/llvm-commits/attachments/20210622/29229e80/attachment.bin>
More information about the llvm-commits
mailing list