From 0ba457138d181f0e9f6770e4750184d3eb8697a5 Mon Sep 17 00:00:00 2001 From: Florian Hahn Date: Fri, 23 May 2025 13:48:00 +0100 Subject: [PATCH] [Local] Verify opcodes match for all insts passed to mergeFlags (NFC). --- llvm/include/llvm/Transforms/Utils/Local.h | 6 ++++++ llvm/lib/Transforms/Utils/Local.cpp | 7 +++++++ 2 files changed, 13 insertions(+) diff --git a/llvm/include/llvm/Transforms/Utils/Local.h b/llvm/include/llvm/Transforms/Utils/Local.h index 9214aad4e6aec..6162557496405 100644 --- a/llvm/include/llvm/Transforms/Utils/Local.h +++ b/llvm/include/llvm/Transforms/Utils/Local.h @@ -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 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. diff --git a/llvm/lib/Transforms/Utils/Local.cpp b/llvm/lib/Transforms/Utils/Local.cpp index 69dcd30d1af99..fe1391a501b43 100644 --- a/llvm/lib/Transforms/Utils/Local.cpp +++ b/llvm/lib/Transforms/Utils/Local.cpp @@ -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(&I)) { HasNUW &= I.hasNoUnsignedWrap(); HasNSW &= I.hasNoSignedWrap();