Skip to content

[llvm-diff] Diff attributes & metadata #129247

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 7 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
53 changes: 53 additions & 0 deletions llvm/test/tools/llvm-diff/call-attributes.ll
Original file line number Diff line number Diff line change
@@ -0,0 +1,53 @@
; RUN: rm -f %t.ll
; RUN: cat %s | sed -e 's/zeroext/signext/' -e 's/noundef/noalias/' -e 's/nounwind/nosync/' > %t.ll
; RUN: not llvm-diff %s %t.ll 2>&1 | FileCheck %s
; CHECK:in function return:
; CHECK: in block %entry:
; CHECK: > %1 = call signext i32 @foo(ptr %0)
; CHECK: > ret i32 %1
; CHECK: < %1 = call zeroext i32 @foo(ptr %0)
; CHECK: < ret i32 %1
; CHECK:in function param:
; CHECK: in block %entry:
; CHECK: > %1 = call i32 @foo(ptr noalias %0)
; CHECK: > ret i32 %1
; CHECK: < %1 = call i32 @foo(ptr noundef %0)
; CHECK: < ret i32 %1
; CHECK:in function function:
; CHECK: in block %entry:
; CHECK: > %1 = call i32 @foo(ptr %0) #0
; CHECK: > ret i32 %1
; CHECK: < %1 = call i32 @foo(ptr %0) #0
; CHECK: < ret i32 %1
; CHECK:in function all_possible:
; CHECK: in block %entry:
; CHECK: > %1 = call signext i32 @foo(ptr noalias %0) #0
; CHECK: > ret i32 %1
; CHECK: < %1 = call zeroext i32 @foo(ptr noundef %0) #0
; CHECK: < ret i32 %1

declare i32 @foo(ptr)

define i32 @return(ptr %0) {
entry:
%1 = call zeroext i32 @foo(ptr %0)
ret i32 %1
}

define i32 @param(ptr %0) {
entry:
%1 = call i32 @foo(ptr noundef %0)
ret i32 %1
}

define i32 @function(ptr %0) {
entry:
%1 = call i32 @foo(ptr %0) nounwind
ret i32 %1
}

define i32 @all_possible(ptr %0) {
entry:
%1 = call zeroext i32 @foo(ptr noundef %0) nounwind
ret i32 %1
}
18 changes: 18 additions & 0 deletions llvm/test/tools/llvm-diff/instruction-metadata.ll
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
; RUN: rm -f %t.ll
; RUN: cat %s | sed -e 's/!range !0/!range !1/' > %t.ll
; RUN: not llvm-diff %s %t.ll 2>&1 | FileCheck %s
; CHECK:in function foo:
; CHECK: in block %entry:
; CHECK: > %sum = add i32 %a, %b, !range !0
; CHECK: > ret i32 %sum
; CHECK: < %sum = add i32 %a, %b, !range !0
; CHECK: < ret i32 %sum

define i32 @foo(i32 %a, i32 %b) {
entry:
%sum = add i32 %a, %b, !range !0
ret i32 %sum
}

!0 = !{i32 0, i32 2147483647}
!1 = !{}
55 changes: 53 additions & 2 deletions llvm/tools/llvm-diff/lib/DifferenceEngine.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -340,8 +340,32 @@ class FunctionDifferenceEngine {
BasicBlock::const_iterator RI);

bool diffCallSites(const CallBase &L, const CallBase &R, bool Complain) {
// FIXME: call attributes
AssumptionContext AC = {L.getParent(), R.getParent()};
const AttributeList &LAttrs = L.getAttributes();
const AttributeList &RAttrs = R.getAttributes();
if (LAttrs.getFnAttrs() != RAttrs.getFnAttrs()) {
if (Complain)
Engine.log("function attributes differ");
return true;
}
if (LAttrs.getNumAttrSets() != RAttrs.getNumAttrSets()) {
if (Complain)
Engine.log("parameter attribute counts differ");
return true;
}
for (unsigned I = 0; I != LAttrs.getNumAttrSets(); I++) {
if (LAttrs.getParamAttrs(I) != RAttrs.getParamAttrs(I)) {
if (Complain)
Engine.logf("parameter attributes %l and %r differ")
<< L.getArgOperand(I) << R.getArgOperand(I);
return true;
}
}
if (LAttrs.getRetAttrs() != RAttrs.getRetAttrs()) {
if (Complain)
Engine.log("return attributes differ");
return true;
}
if (!equivalentAsOperands(L.getCalledOperand(), R.getCalledOperand(),
&AC)) {
if (Complain) Engine.log("called functions differ");
Expand All @@ -366,7 +390,6 @@ class FunctionDifferenceEngine {
// assumption to be checked later in BlockDiffCandidates.
bool diff(const Instruction *L, const Instruction *R, bool Complain,
bool TryUnify, bool AllowAssumptions) {
// FIXME: metadata (if Complain is set)
AssumptionContext ACValue = {L->getParent(), R->getParent()};
// nullptr AssumptionContext disables assumption generation.
const AssumptionContext *AC = AllowAssumptions ? &ACValue : nullptr;
Expand All @@ -377,6 +400,34 @@ class FunctionDifferenceEngine {
return true;
}

if (L->hasMetadata() || R->hasMetadata()) {
SmallVector<std::pair<unsigned, MDNode *>, 4> LMD, RMD;
L->getAllMetadata(LMD);
R->getAllMetadata(RMD);
if (LMD.size() != RMD.size()) {
if (Complain)
Engine.log("different metadata entry counts");
return true;
}
for (unsigned I = 0; I != LMD.size(); ++I) {
if (LMD[I].second->getNumOperands() !=
RMD[I].second->getNumOperands()) {
if (Complain)
Engine.log("different metadata operand counts");
return true;
}
for (unsigned J = 0; J != LMD[I].second->getNumOperands(); J++) {
Metadata *a = LMD[I].second->getOperand(J);
Metadata *b = RMD[I].second->getOperand(J);
if (a->getMetadataID() != b->getMetadataID()) {
if (Complain)
Engine.log("different metadata entry counts");
return true;
}
}
}
}

if (isa<CmpInst>(L)) {
if (cast<CmpInst>(L)->getPredicate()
!= cast<CmpInst>(R)->getPredicate()) {
Expand Down