[llvm] 319c9f6 - [MemoryBuiltins] Added support for memalign
Dávid Bolvanský via llvm-commits
llvm-commits at lists.llvm.org
Tue Apr 20 03:40:31 PDT 2021
Author: Dávid Bolvanský
Date: 2021-04-20T12:39:54+02:00
New Revision: 319c9f6e5884c69903b4140098a4d378b97abc7c
URL: https://github.com/llvm/llvm-project/commit/319c9f6e5884c69903b4140098a4d378b97abc7c
DIFF: https://github.com/llvm/llvm-project/commit/319c9f6e5884c69903b4140098a4d378b97abc7c.diff
LOG: [MemoryBuiltins] Added support for memalign
memalign is older aligned_alloc.
Added:
Modified:
llvm/lib/Analysis/MemoryBuiltins.cpp
llvm/test/Transforms/InstCombine/deref-alloc-fns.ll
Removed:
################################################################################
diff --git a/llvm/lib/Analysis/MemoryBuiltins.cpp b/llvm/lib/Analysis/MemoryBuiltins.cpp
index 51a59efb94f3..7adadb762b84 100644
--- a/llvm/lib/Analysis/MemoryBuiltins.cpp
+++ b/llvm/lib/Analysis/MemoryBuiltins.cpp
@@ -103,6 +103,7 @@ static const std::pair<LibFunc, AllocFnsTy> AllocationFnData[] = {
{LibFunc_msvc_new_array_longlong, {OpNewLike, 1, 0, -1}}, // new[](unsigned long long)
{LibFunc_msvc_new_array_longlong_nothrow, {MallocLike, 2, 0, -1}}, // new[](unsigned long long, nothrow)
{LibFunc_aligned_alloc, {AlignedAllocLike, 2, 1, -1}},
+ {LibFunc_memalign, {AlignedAllocLike, 2, 1, -1}},
{LibFunc_calloc, {CallocLike, 2, 0, 1}},
{LibFunc_vec_calloc, {CallocLike, 2, 0, 1}},
{LibFunc_realloc, {ReallocLike, 2, 1, -1}},
diff --git a/llvm/test/Transforms/InstCombine/deref-alloc-fns.ll b/llvm/test/Transforms/InstCombine/deref-alloc-fns.ll
index b660e6b4c0d9..b1901a1783df 100644
--- a/llvm/test/Transforms/InstCombine/deref-alloc-fns.ll
+++ b/llvm/test/Transforms/InstCombine/deref-alloc-fns.ll
@@ -1,5 +1,7 @@
; NOTE: Assertions have been autogenerated by utils/update_test_checks.py
; RUN: opt -instcombine -S < %s | FileCheck %s
+; RUN: opt -mtriple=x86_64-unknown-linux-gnu < %s -instcombine -S | FileCheck %s --check-prefixes=CHECK,GNU
+
declare noalias i8* @malloc(i64)
declare noalias i8* @calloc(i64, i64)
@@ -8,6 +10,7 @@ declare noalias nonnull i8* @_Znam(i64) ; throwing version of 'new'
declare noalias nonnull i8* @_Znwm(i64) ; throwing version of 'new'
declare noalias i8* @strdup(i8*)
declare noalias i8* @aligned_alloc(i64, i64)
+declare noalias i8* @memalign(i64, i64)
@.str = private unnamed_addr constant [6 x i8] c"hello\00", align 1
@@ -60,6 +63,15 @@ define noalias i8* @aligned_alloc_unknown_size_possibly_zero(i1 %c) {
ret i8* %call
}
+define noalias i8* @aligned_alloc_unknown_align(i64 %align) {
+; CHECK-LABEL: @aligned_alloc_unknown_align(
+; CHECK-NEXT: [[CALL:%.*]] = tail call noalias dereferenceable_or_null(128) i8* @aligned_alloc(i64 [[ALIGN:%.*]], i64 128)
+; CHECK-NEXT: ret i8* [[CALL]]
+;
+ %call = tail call noalias i8* @aligned_alloc(i64 %align, i64 128)
+ ret i8* %call
+}
+
declare noalias i8* @foo(i8*, i8*, i8*)
define noalias i8* @aligned_alloc_dynamic_args(i64 %align, i64 %size) {
@@ -78,6 +90,46 @@ define noalias i8* @aligned_alloc_dynamic_args(i64 %align, i64 %size) {
ret i8* %call
}
+define noalias i8* @memalign_constant_size() {
+; GNU-LABEL: @memalign_constant_size(
+; GNU-NEXT: [[CALL:%.*]] = tail call noalias align 32 dereferenceable_or_null(512) i8* @memalign(i64 32, i64 512)
+; GNU-NEXT: ret i8* [[CALL]]
+;
+ %call = tail call noalias i8* @memalign(i64 32, i64 512)
+ ret i8* %call
+}
+
+define noalias i8* @memalign_unknown_size_nonzero(i1 %c) {
+; GNU-LABEL: @memalign_unknown_size_nonzero(
+; GNU-NEXT: [[SIZE:%.*]] = select i1 [[C:%.*]], i64 64, i64 128
+; GNU-NEXT: [[CALL:%.*]] = tail call noalias align 32 i8* @memalign(i64 32, i64 [[SIZE]])
+; GNU-NEXT: ret i8* [[CALL]]
+;
+ %size = select i1 %c, i64 64, i64 128
+ %call = tail call noalias i8* @memalign(i64 32, i64 %size)
+ ret i8* %call
+}
+
+define noalias i8* @memalign_unknown_size_possibly_zero(i1 %c) {
+; CHECK-LABEL: @memalign_unknown_size_possibly_zero(
+; CHECK-NEXT: [[SIZE:%.*]] = select i1 [[C:%.*]], i64 64, i64 0
+; CHECK-NEXT: [[CALL:%.*]] = tail call noalias i8* @memalign(i64 32, i64 [[SIZE]])
+; CHECK-NEXT: ret i8* [[CALL]]
+;
+ %size = select i1 %c, i64 64, i64 0
+ %call = tail call noalias i8* @memalign(i64 32, i64 %size)
+ ret i8* %call
+}
+
+define noalias i8* @memalign_unknown_align(i64 %align) {
+; GNU-LABEL: @memalign_unknown_align(
+; GNU-NEXT: [[CALL:%.*]] = tail call noalias dereferenceable_or_null(128) i8* @memalign(i64 [[ALIGN:%.*]], i64 128)
+; GNU-NEXT: ret i8* [[CALL]]
+;
+ %call = tail call noalias i8* @memalign(i64 %align, i64 128)
+ ret i8* %call
+}
+
define noalias i8* @malloc_constant_size2() {
; CHECK-LABEL: @malloc_constant_size2(
; CHECK-NEXT: [[CALL:%.*]] = tail call noalias dereferenceable_or_null(80) i8* @malloc(i64 40)
More information about the llvm-commits
mailing list