[MemLoc] Support bcmp in MemoryLocation::getForArgument

Reviewed By: fhahn

Differential Revision: https://reviews.llvm.org/D87964
This commit is contained in:
Dávid Bolvanský 2020-09-19 17:11:06 +02:00
parent 534e9132af
commit d716f1608c
3 changed files with 106 additions and 6 deletions

View File

@ -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()),

View File

@ -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
}

View File

@ -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
}