2023-04-14 22:37:55 +02:00

57 lines
2.2 KiB
LLVM

; NOTE: Assertions have been autogenerated by utils/update_test_checks.py
; RUN: opt -passes='instcombine,simplifycfg' -S < %s | FileCheck %s
@.str = private constant [7 x i8] c"abcdef\00", align 1
declare ptr @memchr(ptr noundef, i32 noundef, i64 noundef)
declare i32 @foo()
define i32 @memchr_to_switch_br(i32 %a) {
; CHECK-LABEL: @memchr_to_switch_br(
; CHECK-NEXT: entry:
; CHECK-NEXT: [[CALL:%.*]] = call ptr @memchr(ptr noundef nonnull dereferenceable(1) @.str, i32 noundef [[A:%.*]], i64 noundef 6)
; CHECK-NEXT: [[CMP_NOT:%.*]] = icmp eq ptr [[CALL]], null
; CHECK-NEXT: br i1 [[CMP_NOT]], label [[RETURN:%.*]], label [[IF_THEN:%.*]]
; CHECK: if.then:
; CHECK-NEXT: [[CALL1:%.*]] = call i32 @foo()
; CHECK-NEXT: br label [[RETURN]]
; CHECK: return:
; CHECK-NEXT: [[RETVAL_0:%.*]] = phi i32 [ [[CALL1]], [[IF_THEN]] ], [ -1, [[ENTRY:%.*]] ]
; CHECK-NEXT: ret i32 [[RETVAL_0]]
;
entry:
%call = call ptr @memchr(ptr noundef nonnull @.str, i32 noundef %a, i64 noundef 6) #3
%cmp.not = icmp eq ptr %call, null
br i1 %cmp.not, label %return, label %if.then
if.then: ; preds = %entry
%call1 = call i32 @foo() #3
br label %return
return: ; preds = %entry, %if.then
%retval.0 = phi i32 [ %call1, %if.then ], [ -1, %entry ]
ret i32 %retval.0
}
define i1 @memchr_to_switch_eq_ret(i32 %c) {
; CHECK-LABEL: @memchr_to_switch_eq_ret(
; CHECK-NEXT: [[P:%.*]] = tail call ptr @memchr(ptr noundef nonnull dereferenceable(1) @.str, i32 noundef [[C:%.*]], i64 noundef 6)
; CHECK-NEXT: [[RET:%.*]] = icmp eq ptr [[P]], null
; CHECK-NEXT: ret i1 [[RET]]
;
%p = tail call ptr @memchr(ptr noundef nonnull @.str, i32 noundef %c, i64 noundef 6)
%ret = icmp eq ptr %p, null
ret i1 %ret
}
define i1 @memchr_to_switch_ne_ret(i32 %c) {
; CHECK-LABEL: @memchr_to_switch_ne_ret(
; CHECK-NEXT: [[P:%.*]] = tail call ptr @memchr(ptr noundef nonnull dereferenceable(1) @.str, i32 noundef [[C:%.*]], i64 noundef 6)
; CHECK-NEXT: [[RET:%.*]] = icmp ne ptr [[P]], null
; CHECK-NEXT: ret i1 [[RET]]
;
%p = tail call ptr @memchr(ptr noundef nonnull @.str, i32 noundef %c, i64 noundef 6)
%ret = icmp ne ptr %p, null
ret i1 %ret
}