1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219
|
; NOTE: Assertions have been autogenerated by utils/update_test_checks.py
; RUN: opt -passes=instcombine,lower-constant-intrinsics -S < %s | FileCheck %s
target datalayout = "e-m:e-p270:32:32-p271:32:32-p272:64:64-i64:64-f80:128-n8:16:32:64-S128"
target triple = "x86_64-unknown-linux-gnu"
declare dso_local i32 @posix_memalign(ptr noundef, i64 noundef, i64 noundef)
declare i64 @llvm.objectsize.i64.p0(ptr, i1 immarg, i1 immarg, i1 immarg)
; Check posix_memalign call with proper handlig of return value
define dso_local i64 @check_posix_memalign(i32 noundef %n) local_unnamed_addr {
; CHECK-LABEL: @check_posix_memalign(
; CHECK-NEXT: entry:
; CHECK-NEXT: [[OBJ:%.*]] = alloca ptr, align 8
; CHECK-NEXT: [[CALL:%.*]] = call i32 @posix_memalign(ptr noundef nonnull [[OBJ]], i64 noundef 8, i64 noundef 10)
; CHECK-NEXT: [[TOBOOL_NOT:%.*]] = icmp eq i32 [[CALL]], 0
; CHECK-NEXT: br i1 [[TOBOOL_NOT]], label [[COND_FALSE:%.*]], label [[EXIT:%.*]]
; CHECK: cond.false:
; CHECK-NEXT: br label [[EXIT]]
; CHECK: exit:
; CHECK-NEXT: [[COND:%.*]] = phi i64 [ -2, [[ENTRY:%.*]] ], [ 10, [[COND_FALSE]] ]
; CHECK-NEXT: ret i64 [[COND]]
;
entry:
%obj = alloca ptr
%call = call i32 @posix_memalign(ptr noundef %obj, i64 noundef 8, i64 noundef 10)
%tobool = icmp ne i32 %call, 0
br i1 %tobool, label %exit, label %cond.false
cond.false:
%val = load ptr, ptr %obj
%objsize = call i64 @llvm.objectsize.i64.p0(ptr %val, i1 false, i1 true, i1 false)
br label %exit
exit:
%cond = phi i64 [ -2, %entry ], [ %objsize, %cond.false ]
ret i64 %cond
}
; Same test case as above but with idiomatic NULL initialization
define dso_local i64 @check_posix_memalign_null() {
; CHECK-LABEL: @check_posix_memalign_null(
; CHECK-NEXT: entry:
; CHECK-NEXT: [[OBJ:%.*]] = alloca ptr, align 8
; CHECK-NEXT: store ptr null, ptr [[OBJ]], align 8
; CHECK-NEXT: [[CALL:%.*]] = call i32 @posix_memalign(ptr noundef nonnull [[OBJ]], i64 noundef 8, i64 noundef 10)
; CHECK-NEXT: [[TOBOOL_NOT:%.*]] = icmp eq i32 [[CALL]], 0
; CHECK-NEXT: br i1 [[TOBOOL_NOT]], label [[COND_FALSE:%.*]], label [[EXIT:%.*]]
; CHECK: cond.false:
; CHECK-NEXT: br label [[EXIT]]
; CHECK: exit:
; CHECK-NEXT: [[COND:%.*]] = phi i64 [ -2, [[ENTRY:%.*]] ], [ 10, [[COND_FALSE]] ]
; CHECK-NEXT: ret i64 [[COND]]
;
entry:
%obj = alloca ptr
store ptr null, ptr %obj
%call = call i32 @posix_memalign(ptr noundef %obj, i64 noundef 8, i64 noundef 10)
%tobool = icmp ne i32 %call, 0
br i1 %tobool, label %exit, label %cond.false
cond.false:
%val = load ptr, ptr %obj
%objsize = call i64 @llvm.objectsize.i64.p0(ptr %val, i1 false, i1 true, i1 false)
br label %exit
exit:
%cond = phi i64 [ -2, %entry ], [ %objsize, %cond.false ]
ret i64 %cond
}
; Using argument storage instead of local storage for the allocated pointer.
define dso_local i64 @check_posix_memalign_arg(ptr noalias noundef %obj) {
; CHECK-LABEL: @check_posix_memalign_arg(
; CHECK-NEXT: entry:
; CHECK-NEXT: [[CALL:%.*]] = call i32 @posix_memalign(ptr noundef [[OBJ:%.*]], i64 noundef 8, i64 noundef 10)
; CHECK-NEXT: [[TOBOOL_NOT:%.*]] = icmp eq i32 [[CALL]], 0
; CHECK-NEXT: br i1 [[TOBOOL_NOT]], label [[COND_FALSE:%.*]], label [[EXIT:%.*]]
; CHECK: cond.false:
; CHECK-NEXT: br label [[EXIT]]
; CHECK: exit:
; CHECK-NEXT: [[COND:%.*]] = phi i64 [ -2, [[ENTRY:%.*]] ], [ 10, [[COND_FALSE]] ]
; CHECK-NEXT: ret i64 [[COND]]
;
entry:
%call = call i32 @posix_memalign(ptr noundef %obj, i64 noundef 8, i64 noundef 10)
%tobool = icmp ne i32 %call, 0
br i1 %tobool, label %exit, label %cond.false
cond.false:
%val = load ptr, ptr %obj
%objsize = call i64 @llvm.objectsize.i64.p0(ptr %val, i1 false, i1 true, i1 false)
br label %exit
exit:
%cond = phi i64 [ -2, %entry ], [ %objsize, %cond.false ]
ret i64 %cond
}
; posix_memalign can fail, in that case no object_size can be guessed.
define dso_local i64 @check_posix_memalign_unchecked() {
; CHECK-LABEL: @check_posix_memalign_unchecked(
; CHECK-NEXT: entry:
; CHECK-NEXT: [[OBJ:%.*]] = alloca ptr, align 8
; CHECK-NEXT: [[CALL:%.*]] = call i32 @posix_memalign(ptr noundef nonnull [[OBJ]], i64 noundef 8, i64 noundef 10)
; CHECK-NEXT: [[VAL:%.*]] = load ptr, ptr [[OBJ]], align 8
; CHECK-NEXT: ret i64 -1
;
entry:
%obj = alloca ptr
%call = call i32 @posix_memalign(ptr noundef %obj, i64 noundef 8, i64 noundef 10)
%val = load ptr, ptr %obj
%objsize = call i64 @llvm.objectsize.i64.p0(ptr %val, i1 false, i1 true, i1 false)
ret i64 %objsize
}
; Checks that bo upon posix_memalign failure behaves correctly
define dso_local i64 @check_posix_memalign_inverted_cond() {
; CHECK-LABEL: @check_posix_memalign_inverted_cond(
; CHECK-NEXT: entry:
; CHECK-NEXT: [[OBJ:%.*]] = alloca ptr, align 8
; CHECK-NEXT: store ptr null, ptr [[OBJ]], align 8
; CHECK-NEXT: [[CALL:%.*]] = call i32 @posix_memalign(ptr noundef nonnull [[OBJ]], i64 noundef 8, i64 noundef 10)
; CHECK-NEXT: [[TOBOOL:%.*]] = icmp eq i32 [[CALL]], 0
; CHECK-NEXT: br i1 [[TOBOOL]], label [[EXIT:%.*]], label [[COND_FALSE:%.*]]
; CHECK: cond.false:
; CHECK-NEXT: [[VAL:%.*]] = load ptr, ptr [[OBJ]], align 8
; CHECK-NEXT: br label [[EXIT]]
; CHECK: exit:
; CHECK-NEXT: [[COND:%.*]] = phi i64 [ -2, [[ENTRY:%.*]] ], [ -1, [[COND_FALSE]] ]
; CHECK-NEXT: ret i64 [[COND]]
;
entry:
%obj = alloca ptr
store ptr null, ptr %obj
%call = call i32 @posix_memalign(ptr noundef %obj, i64 noundef 8, i64 noundef 10)
%tobool = icmp eq i32 %call, 0
br i1 %tobool, label %exit, label %cond.false
cond.false:
%val = load ptr, ptr %obj
%objsize = call i64 @llvm.objectsize.i64.p0(ptr %val, i1 false, i1 true, i1 false)
br label %exit
exit:
%cond = phi i64 [ -2, %entry ], [ %objsize, %cond.false ]
ret i64 %cond
}
; Check posix_memalign call with a runtime condition check
define dso_local i64 @check_posix_memalign_runtime_cond(i32 noundef %n) local_unnamed_addr {
; CHECK-LABEL: @check_posix_memalign_runtime_cond(
; CHECK-NEXT: entry:
; CHECK-NEXT: [[OBJ:%.*]] = alloca ptr, align 8
; CHECK-NEXT: [[CALL:%.*]] = call i32 @posix_memalign(ptr noundef nonnull [[OBJ]], i64 noundef 8, i64 noundef 10)
; CHECK-NEXT: [[TOBOOL_NOT:%.*]] = icmp eq i32 [[CALL]], [[N:%.*]]
; CHECK-NEXT: br i1 [[TOBOOL_NOT]], label [[COND_FALSE:%.*]], label [[EXIT:%.*]]
; CHECK: cond.false:
; CHECK-NEXT: [[VAL:%.*]] = load ptr, ptr [[OBJ]], align 8
; CHECK-NEXT: br label [[EXIT]]
; CHECK: exit:
; CHECK-NEXT: [[COND:%.*]] = phi i64 [ -2, [[ENTRY:%.*]] ], [ -1, [[COND_FALSE]] ]
; CHECK-NEXT: ret i64 [[COND]]
;
entry:
%obj = alloca ptr
%call = call i32 @posix_memalign(ptr noundef %obj, i64 noundef 8, i64 noundef 10)
%tobool = icmp ne i32 %call, %n
br i1 %tobool, label %exit, label %cond.false
cond.false:
%val = load ptr, ptr %obj
%objsize = call i64 @llvm.objectsize.i64.p0(ptr %val, i1 false, i1 true, i1 false)
br label %exit
exit:
%cond = phi i64 [ -2, %entry ], [ %objsize, %cond.false ]
ret i64 %cond
}
; Check posix_memalign call with two different paths leading to the same alloc.
define dso_local i64 @check_posix_memalign_diamond() local_unnamed_addr {
; CHECK-LABEL: @check_posix_memalign_diamond(
; CHECK-NEXT: entry:
; CHECK-NEXT: [[OBJ:%.*]] = alloca ptr, align 8
; CHECK-NEXT: [[CALL:%.*]] = call i32 @posix_memalign(ptr noundef nonnull [[OBJ]], i64 noundef 8, i64 noundef 10)
; CHECK-NEXT: [[TOBOOL_NOT:%.*]] = icmp eq i32 [[CALL]], 0
; CHECK-NEXT: br i1 [[TOBOOL_NOT]], label [[COND_FALSE:%.*]], label [[COND_TRUE:%.*]]
; CHECK: cond.true:
; CHECK-NEXT: br label [[EXIT:%.*]]
; CHECK: cond.false:
; CHECK-NEXT: br label [[EXIT]]
; CHECK: exit:
; CHECK-NEXT: [[COND:%.*]] = phi i64 [ -2, [[COND_TRUE]] ], [ 10, [[COND_FALSE]] ]
; CHECK-NEXT: ret i64 [[COND]]
;
entry:
%obj = alloca ptr
%call = call i32 @posix_memalign(ptr noundef %obj, i64 noundef 8, i64 noundef 10)
%tobool = icmp ne i32 %call, 0
br i1 %tobool, label %cond.true, label %cond.false
cond.true:
br label %exit
cond.false:
%val = load ptr, ptr %obj
%objsize = call i64 @llvm.objectsize.i64.p0(ptr %val, i1 false, i1 true, i1 false)
br label %exit
exit:
%cond = phi i64 [ -2, %cond.true ], [ %objsize, %cond.false ]
ret i64 %cond
}
|