1 ; NOTE: Assertions have been autogenerated by utils/update_test_checks.py
2 ; RUN: opt < %s -passes=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 ptr @example(ptr dereferenceable(24) %x) {
7 ; CHECK-LABEL: @example(
8 ; CHECK-NEXT: ret ptr [[X:%.*]]
10 %y = load ptr, ptr %x, align 8
11 %y_is_null = icmp eq ptr %y, null
13 %res = select i1 %y_is_null, ptr null, ptr %x
15 %nonnull = icmp ne ptr %res, null
16 call void @llvm.assume(i1 %nonnull)
21 ; TODO: this should be folded to `ret ptr %x` as well.
22 define ptr @example2(ptr %x) {
23 ; CHECK-LABEL: @example2(
24 ; CHECK-NEXT: [[Y:%.*]] = load ptr, ptr [[X:%.*]], align 8
25 ; CHECK-NEXT: [[Y_IS_NULL:%.*]] = icmp eq ptr [[Y]], null
26 ; CHECK-NEXT: [[RES:%.*]] = select i1 [[Y_IS_NULL]], ptr null, ptr [[X]]
27 ; CHECK-NEXT: [[NONNULL:%.*]] = icmp ne ptr [[RES]], null
28 ; CHECK-NEXT: call void @llvm.assume(i1 [[NONNULL]])
29 ; CHECK-NEXT: ret ptr [[RES]]
31 %y = load ptr, ptr %x, align 8
32 %y_is_null = icmp eq ptr %y, null
34 %res = select i1 %y_is_null, ptr null, ptr %x
36 %nonnull = icmp ne ptr %res, null
37 call void @llvm.assume(i1 %nonnull)
42 declare void @llvm.assume(i1)