1 ; NOTE: Assertions have been autogenerated by utils/update_test_checks.py
2 ; RUN: opt < %s -instcombine -S | FileCheck %s
3 target datalayout = "e-m:e-p270:32:32-p271:32:32-p272:64:64-i64:64-f80:128-n8:16:32:64-S128"
4 target triple = "x86_64-unknown-linux-gnu"
6 define i8* @example(i8* dereferenceable(24) %x) {
7 ; CHECK-LABEL: @example(
8 ; CHECK-NEXT: [[X2:%.*]] = bitcast i8* [[X:%.*]] to {}**
9 ; CHECK-NEXT: [[Y:%.*]] = load {}*, {}** [[X2]], align 8
10 ; CHECK-NEXT: [[Y_IS_NULL:%.*]] = icmp ne {}* [[Y]], null
11 ; CHECK-NEXT: call void @llvm.assume(i1 [[Y_IS_NULL]])
12 ; CHECK-NEXT: ret i8* [[X]]
14 %x2 = bitcast i8* %x to {}**
15 %y = load {}*, {}** %x2, align 8
16 %y_is_null = icmp eq {}* %y, null
18 %x0 = getelementptr inbounds i8, i8* %x, i64 0
19 %res = select i1 %y_is_null, i8* null, i8* %x0
21 %nonnull = icmp ne i8* %res, null
22 call void @llvm.assume(i1 %nonnull)
27 ; TODO: this should be folded to `ret i8* %x` as well.
28 define i8* @example2(i8* %x) {
29 ; CHECK-LABEL: @example2(
30 ; CHECK-NEXT: [[X2:%.*]] = bitcast i8* [[X:%.*]] to {}**
31 ; CHECK-NEXT: [[Y:%.*]] = load {}*, {}** [[X2]], align 8
32 ; CHECK-NEXT: [[Y_IS_NULL:%.*]] = icmp eq {}* [[Y]], null
33 ; CHECK-NEXT: [[RES:%.*]] = select i1 [[Y_IS_NULL]], i8* null, i8* [[X]]
34 ; CHECK-NEXT: [[NONNULL:%.*]] = icmp ne i8* [[RES]], null
35 ; CHECK-NEXT: call void @llvm.assume(i1 [[NONNULL]])
36 ; CHECK-NEXT: ret i8* [[RES]]
38 %x2 = bitcast i8* %x to {}**
39 %y = load {}*, {}** %x2, align 8
40 %y_is_null = icmp eq {}* %y, null
42 %x0 = getelementptr inbounds i8, i8* %x, i64 0
43 %res = select i1 %y_is_null, i8* null, i8* %x0
45 %nonnull = icmp ne i8* %res, null
46 call void @llvm.assume(i1 %nonnull)
51 declare void @llvm.assume(i1)