Skip to content

[Local] Verify opcodes match for all insts passed to mergeFlags (NFC). #141231

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

Merged
merged 2 commits into from
May 28, 2025
Merged
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
6 changes: 6 additions & 0 deletions llvm/include/llvm/Transforms/Utils/Local.h
Original file line number Diff line number Diff line change
Expand Up @@ -565,6 +565,12 @@ struct OverflowTracking {
bool HasNSW = true;
bool IsDisjoint = true;

#ifndef NDEBUG
/// Opcode of merged instructions. All instructions passed to mergeFlags must
/// have the same opcode.
std::optional<unsigned> Opcode;
#endif

// Note: At the moment, users are responsible to manage AllKnownNonNegative
// and AllKnownNonZero manually. AllKnownNonNegative can be true in a case
// where one of the operands is negative, but one the operators is not NSW.
Expand Down
7 changes: 7 additions & 0 deletions llvm/lib/Transforms/Utils/Local.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -4364,6 +4364,13 @@ bool llvm::inferAttributesFromOthers(Function &F) {
}

void OverflowTracking::mergeFlags(Instruction &I) {
#ifndef NDEBUG
if (Opcode)
assert(Opcode == I.getOpcode() &&
"can only use mergeFlags on instructions with matching opcodes");
else
Opcode = I.getOpcode();
#endif
if (isa<OverflowingBinaryOperator>(&I)) {
HasNUW &= I.hasNoUnsignedWrap();
HasNSW &= I.hasNoSignedWrap();
Expand Down
Loading