[PATCH] D87964: [MemLoc] Support bcmp in MemoryLocation::getForArgument
Dávid Bolvanský via Phabricator via llvm-commits
llvm-commits at lists.llvm.org
Sat Sep 19 07:23:24 PDT 2020
xbolva00 updated this revision to Diff 292959.
xbolva00 added a comment.
Fixed test name.
CHANGES SINCE LAST ACTION
https://reviews.llvm.org/D87964/new/
https://reviews.llvm.org/D87964
Files:
llvm/lib/Analysis/MemoryLocation.cpp
llvm/test/Transforms/DeadStoreElimination/MSSA/libcalls.ll
Index: llvm/test/Transforms/DeadStoreElimination/MSSA/libcalls.ll
===================================================================
--- llvm/test/Transforms/DeadStoreElimination/MSSA/libcalls.ll
+++ llvm/test/Transforms/DeadStoreElimination/MSSA/libcalls.ll
@@ -130,3 +130,64 @@
%res = call i32 @memcmp(i8* nonnull %foo, i8* nonnull %stack.ptr, i64 %n)
ret i32 %res
}
+
+
+declare i32 @bcmp(i8*, i8*, i64)
+
+define i1 @test_bcmp_const_size(i8* noalias %foo) {
+; CHECK-LABEL: @test_bcmp_const_size(
+; CHECK-NEXT: entry:
+; CHECK-NEXT: [[STACK:%.*]] = alloca [10 x i8], align 1
+; CHECK-NEXT: [[STACK_PTR:%.*]] = bitcast [10 x i8]* [[STACK]] to i8*
+; CHECK-NEXT: store i8 49, i8* [[STACK_PTR]], align 1
+; CHECK-NEXT: [[GEP_1:%.*]] = getelementptr i8, i8* [[STACK_PTR]], i64 1
+; CHECK-NEXT: store i8 50, i8* [[GEP_1]], align 1
+; CHECK-NEXT: [[CALL:%.*]] = call i32 @bcmp(i8* nonnull dereferenceable(2) [[FOO:%.*]], i8* nonnull dereferenceable(2) [[STACK_PTR]], i64 2)
+; CHECK-NEXT: [[RES:%.*]] = icmp eq i32 [[CALL]], 0
+; CHECK-NEXT: ret i1 [[RES]]
+;
+entry:
+ %stack = alloca [10 x i8]
+ %stack.ptr = bitcast [10 x i8]* %stack to i8*
+ store i8 49, i8* %stack.ptr, align 1
+ %gep.1 = getelementptr i8, i8* %stack.ptr, i64 1
+ store i8 50, i8* %gep.1, align 1
+ %gep.2 = getelementptr i8, i8* %stack.ptr, i64 2
+ store i8 51, i8* %gep.2, align 1
+ %gep.3 = getelementptr i8, i8* %stack.ptr, i64 3
+ store i8 52, i8* %gep.3, align 1
+ %call = call i32 @bcmp(i8* nonnull dereferenceable(2) %foo, i8* nonnull dereferenceable(2) %stack.ptr, i64 2)
+ %res = icmp eq i32 %call, 0
+ ret i1 %res
+}
+
+define i1 @test_bcmp_variable_size(i8* noalias %foo, i64 %n) {
+; CHECK-LABEL: @test_bcmp_variable_size(
+; CHECK-NEXT: entry:
+; CHECK-NEXT: [[STACK:%.*]] = alloca [10 x i8], align 1
+; CHECK-NEXT: [[STACK_PTR:%.*]] = bitcast [10 x i8]* [[STACK]] to i8*
+; CHECK-NEXT: store i8 49, i8* [[STACK_PTR]], align 1
+; CHECK-NEXT: [[GEP_1:%.*]] = getelementptr i8, i8* [[STACK_PTR]], i64 1
+; CHECK-NEXT: store i8 50, i8* [[GEP_1]], align 1
+; CHECK-NEXT: [[GEP_2:%.*]] = getelementptr i8, i8* [[STACK_PTR]], i64 2
+; CHECK-NEXT: store i8 51, i8* [[GEP_2]], align 1
+; CHECK-NEXT: [[GEP_3:%.*]] = getelementptr i8, i8* [[STACK_PTR]], i64 3
+; CHECK-NEXT: store i8 52, i8* [[GEP_3]], align 1
+; CHECK-NEXT: [[CALL:%.*]] = call i32 @bcmp(i8* nonnull [[FOO:%.*]], i8* nonnull [[STACK_PTR]], i64 [[N:%.*]])
+; CHECK-NEXT: [[RES:%.*]] = icmp eq i32 [[CALL]], 0
+; CHECK-NEXT: ret i1 [[RES]]
+;
+entry:
+ %stack = alloca [10 x i8]
+ %stack.ptr = bitcast [10 x i8]* %stack to i8*
+ store i8 49, i8* %stack.ptr, align 1
+ %gep.1 = getelementptr i8, i8* %stack.ptr, i64 1
+ store i8 50, i8* %gep.1, align 1
+ %gep.2 = getelementptr i8, i8* %stack.ptr, i64 2
+ store i8 51, i8* %gep.2, align 1
+ %gep.3 = getelementptr i8, i8* %stack.ptr, i64 3
+ store i8 52, i8* %gep.3, align 1
+ %call = call i32 @bcmp(i8* nonnull %foo, i8* nonnull %stack.ptr, i64 %n)
+ %res = icmp eq i32 %call, 0
+ ret i1 %res
+}
Index: llvm/lib/Analysis/MemoryLocation.cpp
===================================================================
--- llvm/lib/Analysis/MemoryLocation.cpp
+++ llvm/lib/Analysis/MemoryLocation.cpp
@@ -222,9 +222,10 @@
return MemoryLocation(Arg, LocationSize::precise(LenCI->getZExtValue()),
AATags);
break;
+ case LibFunc_bcmp:
case LibFunc_memcmp:
assert((ArgIdx == 0 || ArgIdx == 1) &&
- "Invalid argument index for memcmp");
+ "Invalid argument index for memcmp/bcmp");
if (const ConstantInt *LenCI =
dyn_cast<ConstantInt>(Call->getArgOperand(2)))
return MemoryLocation(Arg, LocationSize::precise(LenCI->getZExtValue()),
-------------- next part --------------
A non-text attachment was scrubbed...
Name: D87964.292959.patch
Type: text/x-patch
Size: 3820 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/llvm-commits/attachments/20200919/6bbcaf0c/attachment.bin>
More information about the llvm-commits
mailing list