Skip to content

Commit fb923e9

Browse files
authored
[Local] Verify opcodes match for all insts passed to mergeFlags (NFC). (#141231)
The logic for tracking flags relies on all instructions having the same opcode. Add an assert to check, as suggested in #140406. PR: #141231
1 parent 61ec8fc commit fb923e9

File tree

2 files changed

+13
-0
lines changed

2 files changed

+13
-0
lines changed

llvm/include/llvm/Transforms/Utils/Local.h

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -565,6 +565,12 @@ struct OverflowTracking {
565565
bool HasNSW = true;
566566
bool IsDisjoint = true;
567567

568+
#ifndef NDEBUG
569+
/// Opcode of merged instructions. All instructions passed to mergeFlags must
570+
/// have the same opcode.
571+
std::optional<unsigned> Opcode;
572+
#endif
573+
568574
// Note: At the moment, users are responsible to manage AllKnownNonNegative
569575
// and AllKnownNonZero manually. AllKnownNonNegative can be true in a case
570576
// where one of the operands is negative, but one the operators is not NSW.

llvm/lib/Transforms/Utils/Local.cpp

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4364,6 +4364,13 @@ bool llvm::inferAttributesFromOthers(Function &F) {
43644364
}
43654365

43664366
void OverflowTracking::mergeFlags(Instruction &I) {
4367+
#ifndef NDEBUG
4368+
if (Opcode)
4369+
assert(Opcode == I.getOpcode() &&
4370+
"can only use mergeFlags on instructions with matching opcodes");
4371+
else
4372+
Opcode = I.getOpcode();
4373+
#endif
43674374
if (isa<OverflowingBinaryOperator>(&I)) {
43684375
HasNUW &= I.hasNoUnsignedWrap();
43694376
HasNSW &= I.hasNoSignedWrap();

0 commit comments

Comments
 (0)