[llvm] [BasicAA] Track nuw through decomposed expressions (PR #106512)
Nikita Popov via llvm-commits
llvm-commits at lists.llvm.org
Thu Aug 29 02:05:29 PDT 2024
================
@@ -375,24 +375,28 @@ struct LinearExpression {
APInt Scale;
APInt Offset;
+ /// True if all operations in this expression are NUW.
+ bool IsNUW;
/// True if all operations in this expression are NSW.
bool IsNSW;
LinearExpression(const CastedValue &Val, const APInt &Scale,
- const APInt &Offset, bool IsNSW)
- : Val(Val), Scale(Scale), Offset(Offset), IsNSW(IsNSW) {}
+ const APInt &Offset, bool IsNUW, bool IsNSW)
+ : Val(Val), Scale(Scale), Offset(Offset), IsNUW(IsNUW), IsNSW(IsNSW) {}
- LinearExpression(const CastedValue &Val) : Val(Val), IsNSW(true) {
+ LinearExpression(const CastedValue &Val)
+ : Val(Val), IsNUW(true), IsNSW(true) {
unsigned BitWidth = Val.getBitWidth();
Scale = APInt(BitWidth, 1);
Offset = APInt(BitWidth, 0);
}
- LinearExpression mul(const APInt &Other, bool MulIsNSW) const {
+ LinearExpression mul(const APInt &Other, bool MulIsNUW, bool MulIsNSW) const {
// The check for zero offset is necessary, because generally
// (X +nsw Y) *nsw Z does not imply (X *nsw Z) +nsw (Y *nsw Z).
bool NSW = IsNSW && (Other.isOne() || (MulIsNSW && Offset.isZero()));
- return LinearExpression(Val, Scale * Other, Offset * Other, NSW);
+ bool NUW = IsNUW && (Other.isOne() || MulIsNUW);
----------------
nikic wrote:
Proof that mul nuw always distributes (unlike mul nsw): https://alive2.llvm.org/ce/z/MZd_JJ
https://github.com/llvm/llvm-project/pull/106512
More information about the llvm-commits
mailing list