diff options
author | Florian Hahn <flo@fhahn.com> | 2025-05-19 21:47:50 +0100 |
---|---|---|
committer | GitHub <noreply@github.com> | 2025-05-19 21:47:50 +0100 |
commit | c92ff61cee858d0b28f2c3187baa29dd61eb6d87 (patch) | |
tree | 6f375b8b850c4c24e6393fe51130288d4ded7b70 /llvm/lib/Transforms/Utils/Local.cpp | |
parent | 553d4c1d90d9181b647b2028a90f59cdd8ebcb0b (diff) | |
download | llvm-c92ff61cee858d0b28f2c3187baa29dd61eb6d87.zip llvm-c92ff61cee858d0b28f2c3187baa29dd61eb6d87.tar.gz llvm-c92ff61cee858d0b28f2c3187baa29dd61eb6d87.tar.bz2 |
[Local] Move OverflowTracking to Local.h, move logic to helpers (NFC) (#140403)
Move parts of the logic used by Reassociate to OverflowTracking
(mergeFlags & applyFlags) and move the definition to Local.h.
For now it just moves the NUW/NSW handling, as this matches the uses in
LICM. I'll look into the FP math handling separately, as it looks like
there's a difference between Reassociate (takes all flags from I, while
LICM takes the intersection of the flags on both instructions).
PR: https://github.com/llvm/llvm-project/pull/140403
Diffstat (limited to 'llvm/lib/Transforms/Utils/Local.cpp')
-rw-r--r-- | llvm/lib/Transforms/Utils/Local.cpp | 18 |
1 files changed, 18 insertions, 0 deletions
diff --git a/llvm/lib/Transforms/Utils/Local.cpp b/llvm/lib/Transforms/Utils/Local.cpp index 3dbd605..4d168ce 100644 --- a/llvm/lib/Transforms/Utils/Local.cpp +++ b/llvm/lib/Transforms/Utils/Local.cpp @@ -4362,3 +4362,21 @@ bool llvm::inferAttributesFromOthers(Function &F) { return Changed; } + +void OverflowTracking::mergeFlags(Instruction &I) { + if (isa<OverflowingBinaryOperator>(&I)) { + HasNUW &= I.hasNoUnsignedWrap(); + HasNSW &= I.hasNoSignedWrap(); + } +} + +void OverflowTracking::applyFlags(Instruction &I) { + I.clearSubclassOptionalData(); + if (I.getOpcode() == Instruction::Add || + (I.getOpcode() == Instruction::Mul && AllKnownNonZero)) { + if (HasNUW) + I.setHasNoUnsignedWrap(); + if (HasNSW && (AllKnownNonNegative || HasNUW)) + I.setHasNoSignedWrap(); + } +} |