#include "llvm/Pass.h"
#include "llvm/Support/Debug.h"
#include "llvm/Support/DebugCounter.h"
+#include "llvm/Support/MathExtras.h"
#include "llvm/Transforms/Scalar.h"
#include <string>
for (const auto &KV : VariablesB)
R[GetOrAddIndex(KV.second)] -= KV.first;
- R[0] = Offset1 + Offset2 +
- (Pred == (IsSigned ? CmpInst::ICMP_SLT : CmpInst::ICMP_ULT) ? -1 : 0);
+ int64_t OffsetSum;
+ if (AddOverflow(Offset1, Offset2, OffsetSum))
+ return {};
+ if (Pred == (IsSigned ? CmpInst::ICMP_SLT : CmpInst::ICMP_ULT))
+ if (AddOverflow(OffsetSum, int64_t(-1), OffsetSum))
+ return {};
+ R[0] = OffsetSum;
Res.Preconditions = std::move(Preconditions);
return Res;
}
; CHECK-NEXT: call void @llvm.assume(i1 [[NON_ZERO]])
; CHECK-NEXT: [[ADD:%.*]] = sub nuw i64 [[X]], 9223372036854775802
; CHECK-NEXT: [[ULT:%.*]] = icmp ugt i64 200, [[ADD]]
-; CHECK-NEXT: ret i1 false
+; CHECK-NEXT: ret i1 [[ULT]]
;
%non.zero = icmp ugt i64 %x, 0
call void @llvm.assume(i1 %non.zero)