[llvm] d716f16 - [MemLoc] Support bcmp in MemoryLocation::getForArgument
Dávid Bolvanský via llvm-commits
llvm-commits at lists.llvm.org
Sat Sep 19 08:12:59 PDT 2020
Author: Dávid Bolvanský
Date: 2020-09-19T17:12:43+02:00
New Revision: d716f1608cf3bcb4bece20b81ab9204a64a1d67f
URL: https://github.com/llvm/llvm-project/commit/d716f1608cf3bcb4bece20b81ab9204a64a1d67f
DIFF: https://github.com/llvm/llvm-project/commit/d716f1608cf3bcb4bece20b81ab9204a64a1d67f.diff
LOG: [MemLoc] Support bcmp in MemoryLocation::getForArgument
Reviewed By: fhahn
Differential Revision: https://reviews.llvm.org/D87964
Added:
Modified:
llvm/lib/Analysis/MemoryLocation.cpp
llvm/test/Analysis/BasicAA/libfuncs.ll
llvm/test/Transforms/DeadStoreElimination/MSSA/libcalls.ll
Removed:
################################################################################
diff --git a/llvm/lib/Analysis/MemoryLocation.cpp b/llvm/lib/Analysis/MemoryLocation.cpp
index fcea03a118bf..976063c3cda3 100644
--- a/llvm/lib/Analysis/MemoryLocation.cpp
+++ b/llvm/lib/Analysis/MemoryLocation.cpp
@@ -237,9 +237,10 @@ MemoryLocation MemoryLocation::getForArgument(const CallBase *Call,
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()),
diff --git a/llvm/test/Analysis/BasicAA/libfuncs.ll b/llvm/test/Analysis/BasicAA/libfuncs.ll
index 938675ca8bf7..d642613a994c 100644
--- a/llvm/test/Analysis/BasicAA/libfuncs.ll
+++ b/llvm/test/Analysis/BasicAA/libfuncs.ll
@@ -1,7 +1,4 @@
-; RUN: opt -inferattrs -basic-aa -aa-eval -print-all-alias-modref-info -disable-output 2>&1 %s | FileCheck %s
-
-target datalayout = "e-p:64:64:64-i1:8:8-i8:8:8-i16:16:16-i32:32:32-i64:64:64-f32:32:32-f64:64:64-v64:64:64-v128:128:128-a0:0:64-s0:64:64-f80:128:128-n8:16:32:64"
-target triple = "x86_64-apple-macosx10.7"
+; RUN: opt -mtriple=i386-pc-linux-gnu -inferattrs -basic-aa -aa-eval -print-all-alias-modref-info -disable-output 2>&1 %s | FileCheck %s
; CHECK-LABEL: Function: test_memcmp_const_size
; CHECK: Just Ref: Ptr: i8* %a <-> %res = tail call i32 @memcmp(i8* %a, i8* %b, i64 4)
@@ -45,5 +42,47 @@ entry:
ret i32 %res
}
-
declare i32 @memcmp(i8*, i8*, i64)
+declare i32 @bcmp(i8*, i8*, i64)
+
+; CHECK-LABEL: Function: test_bcmp_const_size
+; CHECK: Just Ref: Ptr: i8* %a <-> %res = tail call i32 @bcmp(i8* %a, i8* %b, i64 4)
+; CHECK-NEXT: Just Ref: Ptr: i8* %b <-> %res = tail call i32 @bcmp(i8* %a, i8* %b, i64 4)
+; CHECK-NEXT: Just Ref: Ptr: i8* %a.gep.1 <-> %res = tail call i32 @bcmp(i8* %a, i8* %b, i64 4)
+; CHECK-NEXT: NoModRef: Ptr: i8* %a.gep.5 <-> %res = tail call i32 @bcmp(i8* %a, i8* %b, i64 4)
+; CHECK-NEXT: Just Ref: Ptr: i8* %b.gep.1 <-> %res = tail call i32 @bcmp(i8* %a, i8* %b, i64 4)
+; CHECK-NEXT: NoModRef: Ptr: i8* %b.gep.5 <-> %res = tail call i32 @bcmp(i8* %a, i8* %b, i64 4)
+define i32 @test_bcmp_const_size(i8* noalias %a, i8* noalias %b) {
+entry:
+ %res = tail call i32 @bcmp(i8* %a, i8* %b, i64 4)
+ %a.gep.1 = getelementptr i8, i8* %a, i32 1
+ store i8 0, i8* %a.gep.1
+ %a.gep.5 = getelementptr i8, i8* %a, i32 5
+ store i8 1, i8* %a.gep.5
+ %b.gep.1 = getelementptr i8, i8* %b, i32 1
+ store i8 2, i8* %b.gep.1
+ %b.gep.5 = getelementptr i8, i8* %b, i32 5
+ store i8 3, i8* %b.gep.5
+ ret i32 %res
+}
+
+; CHECK-LABEL: Function: test_bcmp_variable_size
+; CHECK: Just Ref: Ptr: i8* %a <-> %res = tail call i32 @bcmp(i8* %a, i8* %b, i64 %n)
+; CHECK-NEXT: Just Ref: Ptr: i8* %b <-> %res = tail call i32 @bcmp(i8* %a, i8* %b, i64 %n)
+; CHECK-NEXT: Just Ref: Ptr: i8* %a.gep.1 <-> %res = tail call i32 @bcmp(i8* %a, i8* %b, i64 %n)
+; CHECK-NEXT: Just Ref: Ptr: i8* %a.gep.5 <-> %res = tail call i32 @bcmp(i8* %a, i8* %b, i64 %n)
+; CHECK-NEXT: Just Ref: Ptr: i8* %b.gep.1 <-> %res = tail call i32 @bcmp(i8* %a, i8* %b, i64 %n)
+; CHECK-NEXT: Just Ref: Ptr: i8* %b.gep.5 <-> %res = tail call i32 @bcmp(i8* %a, i8* %b, i64 %n)
+define i32 @test_bcmp_variable_size(i8* noalias %a, i8* noalias %b, i64 %n) {
+entry:
+ %res = tail call i32 @bcmp(i8* %a, i8* %b, i64 %n)
+ %a.gep.1 = getelementptr i8, i8* %a, i32 1
+ store i8 0, i8* %a.gep.1
+ %a.gep.5 = getelementptr i8, i8* %a, i32 5
+ store i8 1, i8* %a.gep.5
+ %b.gep.1 = getelementptr i8, i8* %b, i32 1
+ store i8 2, i8* %b.gep.1
+ %b.gep.5 = getelementptr i8, i8* %b, i32 5
+ store i8 3, i8* %b.gep.5
+ ret i32 %res
+}
diff --git a/llvm/test/Transforms/DeadStoreElimination/MSSA/libcalls.ll b/llvm/test/Transforms/DeadStoreElimination/MSSA/libcalls.ll
index ac6efd54ddba..7895a73e6e24 100644
--- a/llvm/test/Transforms/DeadStoreElimination/MSSA/libcalls.ll
+++ b/llvm/test/Transforms/DeadStoreElimination/MSSA/libcalls.ll
@@ -130,3 +130,63 @@ entry:
%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
+}
More information about the llvm-commits
mailing list