[llvm] 867bdfe - [InstCombine] remove incompatible attribute when simplifying some lib calls
Zequan Wu via llvm-commits
llvm-commits at lists.llvm.org
Fri Jan 22 17:27:57 PST 2021
Author: Zequan Wu
Date: 2021-01-22T17:27:36-08:00
New Revision: 867bdfeff1786f9f910c7cd4689fe56d9dcdf162
URL: https://github.com/llvm/llvm-project/commit/867bdfeff1786f9f910c7cd4689fe56d9dcdf162
DIFF: https://github.com/llvm/llvm-project/commit/867bdfeff1786f9f910c7cd4689fe56d9dcdf162.diff
LOG: [InstCombine] remove incompatible attribute when simplifying some lib calls
Like D95088, remove incompatible attribute in more lib calls.
Differential Revision: https://reviews.llvm.org/D95278
Added:
Modified:
llvm/lib/Transforms/Utils/SimplifyLibCalls.cpp
llvm/test/Transforms/InstCombine/memcpy-1.ll
llvm/test/Transforms/InstCombine/memcpy_chk-1.ll
llvm/test/Transforms/InstCombine/memmove-1.ll
llvm/test/Transforms/InstCombine/memmove_chk-1.ll
llvm/test/Transforms/InstCombine/memset-1.ll
llvm/test/Transforms/InstCombine/memset_chk-1.ll
llvm/test/Transforms/InstCombine/stpcpy-1.ll
llvm/test/Transforms/InstCombine/strcpy-1.ll
llvm/test/Transforms/InstCombine/strncpy-1.ll
Removed:
################################################################################
diff --git a/llvm/lib/Transforms/Utils/SimplifyLibCalls.cpp b/llvm/lib/Transforms/Utils/SimplifyLibCalls.cpp
index 4cb4e8848523..f9a9dd237b6c 100644
--- a/llvm/lib/Transforms/Utils/SimplifyLibCalls.cpp
+++ b/llvm/lib/Transforms/Utils/SimplifyLibCalls.cpp
@@ -541,6 +541,8 @@ Value *LibCallSimplifier::optimizeStrCpy(CallInst *CI, IRBuilderBase &B) {
B.CreateMemCpy(Dst, Align(1), Src, Align(1),
ConstantInt::get(DL.getIntPtrType(CI->getContext()), Len));
NewCI->setAttributes(CI->getAttributes());
+ NewCI->removeAttributes(AttributeList::ReturnIndex,
+ AttributeFuncs::typeIncompatible(NewCI->getType()));
return Dst;
}
@@ -568,6 +570,8 @@ Value *LibCallSimplifier::optimizeStpCpy(CallInst *CI, IRBuilderBase &B) {
// copy for us. Make a memcpy to copy the nul byte with align = 1.
CallInst *NewCI = B.CreateMemCpy(Dst, Align(1), Src, Align(1), LenV);
NewCI->setAttributes(CI->getAttributes());
+ NewCI->removeAttributes(AttributeList::ReturnIndex,
+ AttributeFuncs::typeIncompatible(NewCI->getType()));
return DstEnd;
}
@@ -627,6 +631,8 @@ Value *LibCallSimplifier::optimizeStrNCpy(CallInst *CI, IRBuilderBase &B) {
CallInst *NewCI = B.CreateMemCpy(Dst, Align(1), Src, Align(1),
ConstantInt::get(DL.getIntPtrType(PT), Len));
NewCI->setAttributes(CI->getAttributes());
+ NewCI->removeAttributes(AttributeList::ReturnIndex,
+ AttributeFuncs::typeIncompatible(NewCI->getType()));
return Dst;
}
@@ -1102,6 +1108,8 @@ Value *LibCallSimplifier::optimizeMemCpy(CallInst *CI, IRBuilderBase &B) {
CallInst *NewCI = B.CreateMemCpy(CI->getArgOperand(0), Align(1),
CI->getArgOperand(1), Align(1), Size);
NewCI->setAttributes(CI->getAttributes());
+ NewCI->removeAttributes(AttributeList::ReturnIndex,
+ AttributeFuncs::typeIncompatible(NewCI->getType()));
return CI->getArgOperand(0);
}
@@ -1169,6 +1177,8 @@ Value *LibCallSimplifier::optimizeMemMove(CallInst *CI, IRBuilderBase &B) {
CallInst *NewCI = B.CreateMemMove(CI->getArgOperand(0), Align(1),
CI->getArgOperand(1), Align(1), Size);
NewCI->setAttributes(CI->getAttributes());
+ NewCI->removeAttributes(AttributeList::ReturnIndex,
+ AttributeFuncs::typeIncompatible(NewCI->getType()));
return CI->getArgOperand(0);
}
@@ -1229,6 +1239,8 @@ Value *LibCallSimplifier::optimizeMemSet(CallInst *CI, IRBuilderBase &B) {
Value *Val = B.CreateIntCast(CI->getArgOperand(1), B.getInt8Ty(), false);
CallInst *NewCI = B.CreateMemSet(CI->getArgOperand(0), Val, Size, Align(1));
NewCI->setAttributes(CI->getAttributes());
+ NewCI->removeAttributes(AttributeList::ReturnIndex,
+ AttributeFuncs::typeIncompatible(NewCI->getType()));
return CI->getArgOperand(0);
}
@@ -3266,6 +3278,8 @@ Value *FortifiedLibCallSimplifier::optimizeMemCpyChk(CallInst *CI,
B.CreateMemCpy(CI->getArgOperand(0), Align(1), CI->getArgOperand(1),
Align(1), CI->getArgOperand(2));
NewCI->setAttributes(CI->getAttributes());
+ NewCI->removeAttributes(AttributeList::ReturnIndex,
+ AttributeFuncs::typeIncompatible(NewCI->getType()));
return CI->getArgOperand(0);
}
return nullptr;
@@ -3278,6 +3292,8 @@ Value *FortifiedLibCallSimplifier::optimizeMemMoveChk(CallInst *CI,
B.CreateMemMove(CI->getArgOperand(0), Align(1), CI->getArgOperand(1),
Align(1), CI->getArgOperand(2));
NewCI->setAttributes(CI->getAttributes());
+ NewCI->removeAttributes(AttributeList::ReturnIndex,
+ AttributeFuncs::typeIncompatible(NewCI->getType()));
return CI->getArgOperand(0);
}
return nullptr;
@@ -3292,6 +3308,8 @@ Value *FortifiedLibCallSimplifier::optimizeMemSetChk(CallInst *CI,
CallInst *NewCI = B.CreateMemSet(CI->getArgOperand(0), Val,
CI->getArgOperand(2), Align(1));
NewCI->setAttributes(CI->getAttributes());
+ NewCI->removeAttributes(AttributeList::ReturnIndex,
+ AttributeFuncs::typeIncompatible(NewCI->getType()));
return CI->getArgOperand(0);
}
return nullptr;
@@ -3305,6 +3323,9 @@ Value *FortifiedLibCallSimplifier::optimizeMemPCpyChk(CallInst *CI,
CI->getArgOperand(2), B, DL, TLI)) {
CallInst *NewCI = cast<CallInst>(Call);
NewCI->setAttributes(CI->getAttributes());
+ NewCI->removeAttributes(
+ AttributeList::ReturnIndex,
+ AttributeFuncs::typeIncompatible(NewCI->getType()));
return NewCI;
}
return nullptr;
diff --git a/llvm/test/Transforms/InstCombine/memcpy-1.ll b/llvm/test/Transforms/InstCombine/memcpy-1.ll
index 789e5ebd7467..5cd02b03f92d 100644
--- a/llvm/test/Transforms/InstCombine/memcpy-1.ll
+++ b/llvm/test/Transforms/InstCombine/memcpy-1.ll
@@ -28,3 +28,12 @@ define i8* @test_simplify2(i8* %mem1, i8* %mem2, i32 %size) strictfp {
%ret = call i8* @memcpy(i8* %mem1, i8* %mem2, i32 %size) strictfp
ret i8* %ret
}
+
+define i8* @test_no_incompatible_attr(i8* %mem1, i8* %mem2, i32 %size) {
+; CHECK-LABEL: @test_no_incompatible_attr(
+; CHECK-NEXT: call void @llvm.memcpy.p0i8.p0i8.i32(i8* align 1 [[MEM1:%.*]], i8* align 1 [[MEM2:%.*]], i32 [[SIZE:%.*]], i1 false)
+; CHECK-NEXT: ret i8* [[MEM1]]
+
+ %ret = call dereferenceable(1) i8* @memcpy(i8* %mem1, i8* %mem2, i32 %size)
+ ret i8* %ret
+}
diff --git a/llvm/test/Transforms/InstCombine/memcpy_chk-1.ll b/llvm/test/Transforms/InstCombine/memcpy_chk-1.ll
index c76e4f61f654..22525d826937 100644
--- a/llvm/test/Transforms/InstCombine/memcpy_chk-1.ll
+++ b/llvm/test/Transforms/InstCombine/memcpy_chk-1.ll
@@ -74,4 +74,15 @@ define i8* @test_simplify_return_indcall(i8* ()* %alloc) {
ret i8* %ret
}
+define i8* @test_no_incompatible_attr(i8* %mem, i32 %val, i32 %size) {
+; CHECK-LABEL: @test_no_incompatible_attr(
+; CHECK-NEXT: call void @llvm.memcpy.p0i8.p0i8.i64(i8* nonnull align 4 dereferenceable(1824) bitcast (%struct.T1* @t1 to i8*), i8* nonnull align 4 dereferenceable(1824) bitcast (%struct.T2* @t2 to i8*), i64 1824, i1 false)
+; CHECK-NEXT: ret i8* bitcast (%struct.T1* @t1 to i8*)
+;
+ %dst = bitcast %struct.T1* @t1 to i8*
+ %src = bitcast %struct.T2* @t2 to i8*
+ %ret = call dereferenceable(1) i8* @__memcpy_chk(i8* %dst, i8* %src, i64 1824, i64 1824)
+ ret i8* %ret
+}
+
declare i8* @__memcpy_chk(i8*, i8*, i64, i64)
diff --git a/llvm/test/Transforms/InstCombine/memmove-1.ll b/llvm/test/Transforms/InstCombine/memmove-1.ll
index 0445a60aeddb..7cd447e136da 100644
--- a/llvm/test/Transforms/InstCombine/memmove-1.ll
+++ b/llvm/test/Transforms/InstCombine/memmove-1.ll
@@ -15,3 +15,11 @@ define i8* @test_simplify1(i8* %mem1, i8* %mem2, i32 %size) {
ret i8* %ret
; CHECK: ret i8* %mem1
}
+
+define i8* @test_no_incompatible_attr(i8* %mem1, i8* %mem2, i32 %size) {
+; CHECK-LABEL: @test_no_incompatible_attr(
+ %ret = call dereferenceable(1) i8* @memmove(i8* %mem1, i8* %mem2, i32 %size)
+; CHECK: call void @llvm.memmove
+ ret i8* %ret
+; CHECK: ret i8* %mem1
+}
diff --git a/llvm/test/Transforms/InstCombine/memmove_chk-1.ll b/llvm/test/Transforms/InstCombine/memmove_chk-1.ll
index 16aa9db812ef..ed15f9306e88 100644
--- a/llvm/test/Transforms/InstCombine/memmove_chk-1.ll
+++ b/llvm/test/Transforms/InstCombine/memmove_chk-1.ll
@@ -66,4 +66,16 @@ define i8* @test_no_simplify2() {
ret i8* %ret
}
+define i8* @test_no_incompatible_attr(i8* %mem, i32 %val, i32 %size) {
+; CHECK-LABEL: @test_no_incompatible_attr(
+; CHECK-NEXT: call void @llvm.memmove.p0i8.p0i8.i64(i8* nonnull align 4 dereferenceable(1824) bitcast (%struct.T1* @t1 to i8*), i8* nonnull align 4 dereferenceable(1824) bitcast (%struct.T2* @t2 to i8*), i64 1824, i1 false)
+; CHECK-NEXT: ret i8* bitcast (%struct.T1* @t1 to i8*)
+;
+ %dst = bitcast %struct.T1* @t1 to i8*
+ %src = bitcast %struct.T2* @t2 to i8*
+
+ %ret = call dereferenceable(1) i8* @__memmove_chk(i8* %dst, i8* %src, i64 1824, i64 1824)
+ ret i8* %ret
+}
+
declare i8* @__memmove_chk(i8*, i8*, i64, i64)
diff --git a/llvm/test/Transforms/InstCombine/memset-1.ll b/llvm/test/Transforms/InstCombine/memset-1.ll
index 9ce8795c6562..2af59ce53c1d 100644
--- a/llvm/test/Transforms/InstCombine/memset-1.ll
+++ b/llvm/test/Transforms/InstCombine/memset-1.ll
@@ -198,6 +198,15 @@ define i8* @memset_attrs4(i1 %b, i8* %ptr, i32 %size) {
ret i8* %memset
}
+define i8* @test_no_incompatible_attr(i8* %mem, i32 %val, i32 %size) {
+; CHECK-LABEL: @test_no_incompatible_attr(
+; CHECK-NEXT: [[TMP1:%.*]] = trunc i32 [[VAL:%.*]] to i8
+; CHECK-NEXT: call void @llvm.memset.p0i8.i32(i8* align 1 [[MEM:%.*]], i8 [[TMP1]], i32 [[SIZE:%.*]], i1 false)
+; CHECK-NEXT: ret i8* [[MEM]]
+;
+ %ret = call dereferenceable(1) i8* @memset(i8* %mem, i32 %val, i32 %size)
+ ret i8* %ret
+}
attributes #0 = { nounwind ssp uwtable }
attributes #1 = { nounwind }
diff --git a/llvm/test/Transforms/InstCombine/memset_chk-1.ll b/llvm/test/Transforms/InstCombine/memset_chk-1.ll
index 75ce19edd91a..bc16dd8b8ff0 100644
--- a/llvm/test/Transforms/InstCombine/memset_chk-1.ll
+++ b/llvm/test/Transforms/InstCombine/memset_chk-1.ll
@@ -141,6 +141,17 @@ cleanup:
}
+define i8* @test_no_incompatible_attr(i8* %mem, i32 %val, i32 %size) {
+; CHECK-LABEL: @test_no_incompatible_attr(
+; CHECK-NEXT: call void @llvm.memset.p0i8.i64(i8* nonnull align 4 dereferenceable(1824) bitcast (%struct.T* @t to i8*), i8 0, i64 1824, i1 false)
+; CHECK-NEXT: ret i8* bitcast (%struct.T* @t to i8*)
+;
+ %dst = bitcast %struct.T* @t to i8*
+
+ %ret = call dereferenceable(1) i8* @__memset_chk(i8* %dst, i32 0, i64 1824, i64 1824)
+ ret i8* %ret
+}
+
declare noalias i8* @malloc(i64) #1
attributes #0 = { nounwind ssp uwtable }
diff --git a/llvm/test/Transforms/InstCombine/stpcpy-1.ll b/llvm/test/Transforms/InstCombine/stpcpy-1.ll
index 260ccf6c0e78..5f3da1b79f1b 100644
--- a/llvm/test/Transforms/InstCombine/stpcpy-1.ll
+++ b/llvm/test/Transforms/InstCombine/stpcpy-1.ll
@@ -62,3 +62,16 @@ define i8* @test_no_simplify1() {
%ret = call i8* @stpcpy(i8* %dst, i8* %src)
ret i8* %ret
}
+
+define i8* @test_no_incompatible_attr() {
+; CHECK-LABEL: @test_no_incompatible_attr(
+; CHECK-NEXT: call void @llvm.memcpy.p0i8.p0i8.i32(i8* nonnull align 1 dereferenceable(6) getelementptr inbounds ([32 x i8], [32 x i8]* @a, i32 0, i32 0), i8* nonnull align 1 dereferenceable(6) getelementptr inbounds ([6 x i8], [6 x i8]* @hello, i32 0, i32 0), i32 6, i1 false)
+; CHECK-NEXT: ret i8* getelementptr inbounds ([32 x i8], [32 x i8]* @a, i32 0, i32 5)
+;
+
+ %dst = getelementptr [32 x i8], [32 x i8]* @a, i32 0, i32 0
+ %src = getelementptr [6 x i8], [6 x i8]* @hello, i32 0, i32 0
+
+ %ret = call dereferenceable(1) i8* @stpcpy(i8* %dst, i8* %src)
+ ret i8* %ret
+}
diff --git a/llvm/test/Transforms/InstCombine/strcpy-1.ll b/llvm/test/Transforms/InstCombine/strcpy-1.ll
index 0ccf983a7314..dd4e77cd8bb9 100644
--- a/llvm/test/Transforms/InstCombine/strcpy-1.ll
+++ b/llvm/test/Transforms/InstCombine/strcpy-1.ll
@@ -62,3 +62,15 @@ define i8* @test_no_simplify1() {
%ret = call i8* @strcpy(i8* %dst, i8* %src)
ret i8* %ret
}
+
+define void @test_no_incompatible_attr() {
+; CHECK-LABEL: @test_no_incompatible_attr(
+; CHECK-NEXT: call void @llvm.memcpy.p0i8.p0i8.i32(i8* nonnull align 1 dereferenceable(6) getelementptr inbounds ([32 x i8], [32 x i8]* @a, i32 0, i32 0), i8* nonnull align 1 dereferenceable(6) getelementptr inbounds ([6 x i8], [6 x i8]* @hello, i32 0, i32 0), i32 6, i1 false)
+; CHECK-NEXT: ret void
+
+ %dst = getelementptr [32 x i8], [32 x i8]* @a, i32 0, i32 0
+ %src = getelementptr [6 x i8], [6 x i8]* @hello, i32 0, i32 0
+
+ call dereferenceable(1) i8* @strcpy(i8* %dst, i8* %src)
+ ret void
+}
diff --git a/llvm/test/Transforms/InstCombine/strncpy-1.ll b/llvm/test/Transforms/InstCombine/strncpy-1.ll
index 5d35f613ea5d..f2e4b62ff5c2 100644
--- a/llvm/test/Transforms/InstCombine/strncpy-1.ll
+++ b/llvm/test/Transforms/InstCombine/strncpy-1.ll
@@ -169,3 +169,15 @@ define void @test_no_simplify2() {
call i8* @strncpy(i8* %dst, i8* %src, i32 8)
ret void
}
+
+define void @test_no_incompatible_attr() {
+; CHECK-LABEL: @test_no_incompatible_attr(
+; CHECK-NEXT: call void @llvm.memcpy.p0i8.p0i8.i32(i8* nonnull align 1 dereferenceable(6) getelementptr inbounds ([32 x i8], [32 x i8]* @a, i32 0, i32 0), i8* nonnull align 1 dereferenceable(6) getelementptr inbounds ([6 x i8], [6 x i8]* @hello, i32 0, i32 0), i32 6, i1 false)
+; CHECK-NEXT: ret void
+;
+ %dst = getelementptr [32 x i8], [32 x i8]* @a, i32 0, i32 0
+ %src = getelementptr [6 x i8], [6 x i8]* @hello, i32 0, i32 0
+
+ call i8* @strncpy(i8* %dst, i8* %src, i32 6)
+ ret void
+}
More information about the llvm-commits
mailing list