Skip to content

Check types when applying inverse cond pattern#323

Merged
viktormalik merged 1 commit intodiffkemp:masterfrom
FrNecas:fnecas-fix-cmp-operations
Mar 26, 2024
Merged

Check types when applying inverse cond pattern#323
viktormalik merged 1 commit intodiffkemp:masterfrom
FrNecas:fnecas-fix-cmp-operations

Conversation

@FrNecas
Copy link
Copy Markdown
Collaborator

@FrNecas FrNecas commented Mar 20, 2024

In certain conditions, not checking the type could lead to an assertion failure in cmpOperationsWithOperands. FunctionComparator::cmpOperations checks the types of operands, however if the instructions are an inverse icmp instructions, Diffkemp discards this result. We need to differentiate, whether the non-zero return code from cmpOperations was caused by a difference in types or difference in values before applying the pattern.

The attached test resulted in an assertion failure with current diffkemp version on this line:

// cmpValues should ensure this is true.
assert(cmpTypes(OpL->getType(), OpR->getType()) == 0);

I thought of two possible solutions to this problem:

  1. the one submitted in this PR
  2. checking type equality in DifferentialFunctionComparator::cmpValues

The second option sounds a bit cleaner but I feel like it could have some side-effects that I may not be aware of (since the method is called quite often from various contexts) and it may be intentional that the comparison is left out. Therefore, I decided to use the "safer" alternative.

@FrNecas FrNecas force-pushed the fnecas-fix-cmp-operations branch from 8e974e4 to 2b575c3 Compare March 25, 2024 14:29
Copy link
Copy Markdown
Collaborator

@viktormalik viktormalik left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Looks great, just one nit. Thanks!

In certain conditions, not checking the type could lead to an assertion
failure in cmpOperationsWithOperands. FunctionComparator::cmpOperations
checks the types of operands, however if the instructions are an inverse
icmp instructions, Diffkemp discards this result. We need to
differentiate, whether the non-zero return code from cmpOperations
was caused by a difference in types or difference in values before
applying the pattern.
@FrNecas FrNecas force-pushed the fnecas-fix-cmp-operations branch from 2b575c3 to 837c8a9 Compare March 26, 2024 08:45
@viktormalik viktormalik merged commit 54deef1 into diffkemp:master Mar 26, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants