[llvm] fb923e9 - [Local] Verify opcodes match for all insts passed to mergeFlags (NFC). (#141231)
via llvm-commits
llvm-commits at lists.llvm.org
Wed May 28 08:03:28 PDT 2025
Author: Florian Hahn
Date: 2025-05-28T16:03:24+01:00
New Revision: fb923e98d13e80d0d1cf878ba5b10da4e81b5cd5
URL: https://github.com/llvm/llvm-project/commit/fb923e98d13e80d0d1cf878ba5b10da4e81b5cd5
DIFF: https://github.com/llvm/llvm-project/commit/fb923e98d13e80d0d1cf878ba5b10da4e81b5cd5.diff
LOG: [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
https://github.com/llvm/llvm-project/pull/140406.
PR: https://github.com/llvm/llvm-project/pull/141231
Added:
Modified:
llvm/include/llvm/Transforms/Utils/Local.h
llvm/lib/Transforms/Utils/Local.cpp
Removed:
################################################################################
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<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.
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<OverflowingBinaryOperator>(&I)) {
HasNUW &= I.hasNoUnsignedWrap();
HasNSW &= I.hasNoSignedWrap();
More information about the llvm-commits
mailing list