[llvm] 9107cd6 - [AutoUpgrade] Don't lose attributes when upgrading mem intrinsics
Alex Richardson via llvm-commits
llvm-commits at lists.llvm.org
Wed Apr 13 02:31:21 PDT 2022
Author: Alex Richardson
Date: 2022-04-13T09:30:10Z
New Revision: 9107cd632d5088076411ae5253f73dcd9cd650e9
URL: https://github.com/llvm/llvm-project/commit/9107cd632d5088076411ae5253f73dcd9cd650e9
DIFF: https://github.com/llvm/llvm-project/commit/9107cd632d5088076411ae5253f73dcd9cd650e9.diff
LOG: [AutoUpgrade] Don't lose attributes when upgrading mem intrinsics
The original AutoUpgrade code from 1e68724d24ba38de7c7cdb2e1939d78c8b37cc0d
did not retain existing attributes. I noticed this in some downstream test
cases, but it turns out there are also two affected testcase upstream.
Differential Revision: https://reviews.llvm.org/D121971
Added:
Modified:
llvm/lib/IR/AutoUpgrade.cpp
llvm/test/Bitcode/upgrade-memory-intrinsics.ll
llvm/test/Transforms/IROutliner/illegal-memset.ll
llvm/test/Transforms/IROutliner/outline-memset.ll
Removed:
################################################################################
diff --git a/llvm/lib/IR/AutoUpgrade.cpp b/llvm/lib/IR/AutoUpgrade.cpp
index b268fad8cd300..fbd08777d8180 100644
--- a/llvm/lib/IR/AutoUpgrade.cpp
+++ b/llvm/lib/IR/AutoUpgrade.cpp
@@ -4077,6 +4077,12 @@ void llvm::UpgradeIntrinsicCall(CallBase *CI, Function *NewFn) {
Value *Args[4] = {CI->getArgOperand(0), CI->getArgOperand(1),
CI->getArgOperand(2), CI->getArgOperand(4)};
NewCall = Builder.CreateCall(NewFn, Args);
+ AttributeList OldAttrs = CI->getAttributes();
+ AttributeList NewAttrs = AttributeList::get(
+ C, OldAttrs.getFnAttrs(), OldAttrs.getRetAttrs(),
+ {OldAttrs.getParamAttrs(0), OldAttrs.getParamAttrs(1),
+ OldAttrs.getParamAttrs(2), OldAttrs.getParamAttrs(4)});
+ NewCall->setAttributes(NewAttrs);
auto *MemCI = cast<MemIntrinsic>(NewCall);
// All mem intrinsics support dest alignment.
const ConstantInt *Align = cast<ConstantInt>(CI->getArgOperand(3));
diff --git a/llvm/test/Bitcode/upgrade-memory-intrinsics.ll b/llvm/test/Bitcode/upgrade-memory-intrinsics.ll
index 21b5efd66bdda..57a41f2f04659 100644
--- a/llvm/test/Bitcode/upgrade-memory-intrinsics.ll
+++ b/llvm/test/Bitcode/upgrade-memory-intrinsics.ll
@@ -27,6 +27,18 @@ define void @test2(i8* %p1, i8* %p2, i8* %p3) {
ret void
}
+; Make sure that attributes are not dropped
+define void @test3(i8* %p1, i8* %p2, i8* %p3) {
+; CHECK-LABEL: @test
+; CHECK: call void @llvm.memset.p0i8.i64(i8* nonnull align 4 %p1, i8 signext 55, i64 zeroext 100, i1 immarg false)
+; CHECK: call void @llvm.memcpy.p0i8.p0i8.i64(i8* nonnull align 4 %p1, i8* readonly align 4 %p2, i64 zeroext 50, i1 immarg false)
+; CHECK: call void @llvm.memmove.p0i8.p0i8.i64(i8* nonnull align 4 %p2, i8* readonly align 4 %p3, i64 zeroext 1000, i1 immarg false)
+ call void @llvm.memset.p0i8.i64(i8* nonnull %p1, i8 signext 55, i64 zeroext 100, i32 signext 4, i1 immarg false)
+ call void @llvm.memcpy.p0i8.p0i8.i64(i8* nonnull %p1, i8* readonly %p2, i64 zeroext 50, i32 signext 4, i1 immarg false)
+ call void @llvm.memmove.p0i8.p0i8.i64(i8* nonnull %p2, i8* readonly %p3, i64 zeroext 1000, i32 signext 4, i1 immarg false)
+ ret void
+}
+
; CHECK: declare void @llvm.memset.p0i8.i64(i8* nocapture writeonly, i8, i64, i1 immarg)
; CHECK: declare void @llvm.memcpy.p0i8.p0i8.i64(i8* noalias nocapture writeonly, i8* noalias nocapture readonly, i64, i1 immarg)
; CHECK: declare void @llvm.memmove.p0i8.p0i8.i64(i8* nocapture writeonly, i8* nocapture readonly, i64, i1 immarg)
diff --git a/llvm/test/Transforms/IROutliner/illegal-memset.ll b/llvm/test/Transforms/IROutliner/illegal-memset.ll
index ed3eeb2d01b4b..473931652887a 100644
--- a/llvm/test/Transforms/IROutliner/illegal-memset.ll
+++ b/llvm/test/Transforms/IROutliner/illegal-memset.ll
@@ -11,7 +11,7 @@ define i64 @function1(i64 %x, i64 %z, i64 %n) {
; CHECK-NEXT: entry:
; CHECK-NEXT: [[POOL:%.*]] = alloca [59 x i64], align 4
; CHECK-NEXT: [[TMP:%.*]] = bitcast [59 x i64]* [[POOL]] to i8*
-; CHECK-NEXT: call void @llvm.memset.p0i8.i64(i8* align 4 [[TMP]], i8 0, i64 236, i1 false)
+; CHECK-NEXT: call void @llvm.memset.p0i8.i64(i8* nonnull align 4 [[TMP]], i8 0, i64 236, i1 false)
; CHECK-NEXT: call void @outlined_ir_func_0(i64 [[N:%.*]], i64 [[X:%.*]], i64 [[Z:%.*]])
; CHECK-NEXT: ret i64 0
;
@@ -30,7 +30,7 @@ define i64 @function2(i64 %x, i64 %z, i64 %n) {
; CHECK-NEXT: entry:
; CHECK-NEXT: [[POOL:%.*]] = alloca [59 x i64], align 4
; CHECK-NEXT: [[TMP:%.*]] = bitcast [59 x i64]* [[POOL]] to i8*
-; CHECK-NEXT: call void @llvm.memset.p0i8.i64(i8* align 4 [[TMP]], i8 0, i64 236, i1 false)
+; CHECK-NEXT: call void @llvm.memset.p0i8.i64(i8* nonnull align 4 [[TMP]], i8 0, i64 236, i1 false)
; CHECK-NEXT: call void @outlined_ir_func_0(i64 [[N:%.*]], i64 [[X:%.*]], i64 [[Z:%.*]])
; CHECK-NEXT: ret i64 0
;
diff --git a/llvm/test/Transforms/IROutliner/outline-memset.ll b/llvm/test/Transforms/IROutliner/outline-memset.ll
index 65dd04978d0a6..5061422660434 100644
--- a/llvm/test/Transforms/IROutliner/outline-memset.ll
+++ b/llvm/test/Transforms/IROutliner/outline-memset.ll
@@ -45,7 +45,7 @@ entry:
; CHECK-NEXT: br label [[ENTRY_TO_OUTLINE:%.*]]
; CHECK: entry_to_outline:
; CHECK-NEXT: [[TMP:%.*]] = bitcast [59 x i64]* [[TMP0:%.*]] to i8*
-; CHECK-NEXT: call void @llvm.memset.p0i8.i64(i8* align 4 [[TMP]], i8 0, i64 236, i1 false)
+; CHECK-NEXT: call void @llvm.memset.p0i8.i64(i8* nonnull align 4 [[TMP]], i8 0, i64 236, i1 false)
; CHECK-NEXT: [[CMP3:%.*]] = icmp eq i64 [[TMP1:%.*]], 0
; CHECK-NEXT: [[A:%.*]] = add i64 [[TMP2:%.*]], [[TMP3:%.*]]
; CHECK-NEXT: [[C:%.*]] = add i64 [[TMP2]], [[TMP3]]
More information about the llvm-commits
mailing list