[llvm] 8daba2c - Skip negative length while inferring initializes attr (#120874)
via llvm-commits
llvm-commits at lists.llvm.org
Sun Dec 22 19:01:55 PST 2024
Author: Haopeng Liu
Date: 2024-12-22T19:01:52-08:00
New Revision: 8daba2c13dc3f4856d064f57a2a56dcf4ea1d7b3
URL: https://github.com/llvm/llvm-project/commit/8daba2c13dc3f4856d064f57a2a56dcf4ea1d7b3
DIFF: https://github.com/llvm/llvm-project/commit/8daba2c13dc3f4856d064f57a2a56dcf4ea1d7b3.diff
LOG: Skip negative length while inferring initializes attr (#120874)
Bail out negative length while inferring initializes attr. Otherwise it
causes an assertion error:
`Attribute 'initializes' does not support unordered ranges`
Added:
Modified:
llvm/lib/Transforms/IPO/FunctionAttrs.cpp
llvm/test/Transforms/FunctionAttrs/initializes.ll
Removed:
################################################################################
diff --git a/llvm/lib/Transforms/IPO/FunctionAttrs.cpp b/llvm/lib/Transforms/IPO/FunctionAttrs.cpp
index afb0ea72b269c8..fe9cca01a8f31f 100644
--- a/llvm/lib/Transforms/IPO/FunctionAttrs.cpp
+++ b/llvm/lib/Transforms/IPO/FunctionAttrs.cpp
@@ -633,7 +633,7 @@ ArgumentAccessInfo getArgmentAccessInfo(const Instruction *I,
[](Value *Length,
std::optional<int64_t> Offset) -> std::optional<ConstantRange> {
auto *ConstantLength = dyn_cast<ConstantInt>(Length);
- if (ConstantLength && Offset)
+ if (ConstantLength && Offset && !ConstantLength->isNegative())
return ConstantRange(
APInt(64, *Offset, true),
APInt(64, *Offset + ConstantLength->getSExtValue(), true));
diff --git a/llvm/test/Transforms/FunctionAttrs/initializes.ll b/llvm/test/Transforms/FunctionAttrs/initializes.ll
index 2aa8385fe4ca7b..c607fbeabb5087 100644
--- a/llvm/test/Transforms/FunctionAttrs/initializes.ll
+++ b/llvm/test/Transforms/FunctionAttrs/initializes.ll
@@ -423,6 +423,17 @@ define void @memset_offset(ptr %p) {
ret void
}
+define void @memset_neg(ptr %p) {
+; CHECK: Function Attrs: mustprogress nofree norecurse nosync nounwind willreturn memory(argmem: write)
+; CHECK-LABEL: define void @memset_neg(
+; CHECK-SAME: ptr nocapture writeonly [[P:%.*]]) #[[ATTR0]] {
+; CHECK-NEXT: call void @llvm.memset.p0.i64(ptr [[P]], i8 2, i64 -1, i1 false)
+; CHECK-NEXT: ret void
+;
+ call void @llvm.memset(ptr %p, i8 2, i64 -1, i1 false)
+ ret void
+}
+
define void @memset_volatile(ptr %p) {
; CHECK: Function Attrs: mustprogress nofree norecurse nounwind willreturn memory(argmem: write)
; CHECK-LABEL: define void @memset_volatile(
More information about the llvm-commits
mailing list