<commit_before>; Replace a 'select' with 'or' in 'select - cmp [eq|ne] - br' sequence
; RUN: opt -instcombine -S < %s | FileCheck %s

%C = type <{ %struct.S }>
%struct.S = type { i64*, i32, i32 }

declare void @bar(%struct.S *) #1
declare void @foobar()

define void @test1(%C*) {
entry:
  %1 = getelementptr inbounds %C, %C* %0, i64 0, i32 0, i32 0
  %m = load i64*, i64** %1, align 8
  %2 = getelementptr inbounds %C, %C* %0, i64 1, i32 0, i32 0
  %n = load i64*, i64** %2, align 8
  %3 = getelementptr inbounds i64, i64* %m, i64 9
  %4 = bitcast i64* %3 to i64 (%C*)**
  %5 = load i64 (%C*)*, i64 (%C*)** %4, align 8
  %6 = icmp eq i64* %m, %n
  %7 = select i1 %6, %C* %0, %C* null
  %8 = icmp eq %C* %7, null
  br i1 %8, label %12, label %10

; <label>:9                                       ; preds = %10, %12
  ret void

; <label>:10                                      ; preds = %entry
  %11 = getelementptr inbounds %C, %C* %7, i64 0, i32 0
  tail call void @bar(%struct.S* %11)
  br label %9

; <label>:12                                      ; preds = %entry
  %13 = tail call i64 %5(%C* %0)
  br label %9
; CHECK-LABEL: @test1(
; CHECK-NOT: select
; CHECK: or
; CHECK-NOT: select
}

define void @test2(%C*) {
entry:
  %1 = getelementptr inbounds %C, %C* %0, i64 0, i32 0, i32 0
  %m = load i64*, i64** %1, align 8
  %2 = getelementptr inbounds %C, %C* %0, i64 1, i32 0, i32 0
  %n = load i64*, i64** %2, align 8
  %3 = getelementptr inbounds i64, i64* %m, i64 9
  %4 = bitcast i64* %3 to i64 (%C*)**
  %5 = load i64 (%C*)*, i64 (%C*)** %4, align 8
  %6 = icmp eq i64* %m, %n
  %7 = select i1 %6, %C* null, %C* %0
  %8 = icmp eq %C* %7, null
  br i1 %8, label %12, label %10

; <label>:9                                       ; preds = %10, %12
  ret void

; <label>:10                                      ; preds = %entry
  %11 = getelementptr inbounds %C, %C* %7, i64 0, i32 0
  tail call void @bar(%struct.S* %11)
  br label %9

; <label>:12                                      ; preds = %entry
  %13 = tail call i64 %5(%C* %0)
  br label %9
; CHECK-LABEL: @test2(
; CHECK-NOT: select
; CHECK: or
; CHECK-NOT: select
}

define void @test3(%C*) {
entry:
  %1 = getelementptr inbounds %C, %C* %0, i64 0, i32 0, i32 0
  %m = load i64*, i64** %1, align 8
  %2 = getelementptr inbounds %C, %C* %0, i64 1, i32 0, i32 0
  %n = load i64*, i64** %2, align 8
  %3 = getelementptr inbounds i64, i64* %m, i64 9
  %4 = bitcast i64* %3 to i64 (%C*)**
  %5 = load i64 (%C*)*, i64 (%C*)** %4, align 8
  %6 = icmp eq i64* %m, %n
  %7 = select i1 %6, %C* %0, %C* null
  %8 = icmp ne %C* %7, null
  br i1 %8, label %10, label %12

; <label>:9                                       ; preds = %10, %12
  ret void

; <label>:10                                      ; preds = %entry
  %11 = getelementptr inbounds %C, %C* %7, i64 0, i32 0
  tail call void @bar(%struct.S* %11)
  br label %9

; <label>:12                                      ; preds = %entry
  %13 = tail call i64 %5(%C* %0)
  br label %9
; CHECK-LABEL: @test3(
; CHECK-NOT: select
; CHECK: or
; CHECK-NOT: select
}

define void @test4(%C*) {
entry:
  %1 = getelementptr inbounds %C, %C* %0, i64 0, i32 0, i32 0
  %m = load i64*, i64** %1, align 8
  %2 = getelementptr inbounds %C, %C* %0, i64 1, i32 0, i32 0
  %n = load i64*, i64** %2, align 8
  %3 = getelementptr inbounds i64, i64* %m, i64 9
  %4 = bitcast i64* %3 to i64 (%C*)**
  %5 = load i64 (%C*)*, i64 (%C*)** %4, align 8
  %6 = icmp eq i64* %m, %n
  %7 = select i1 %6, %C* null, %C* %0
  %8 = icmp ne %C* %7, null
  br i1 %8, label %10, label %12

; <label>:9                                       ; preds = %10, %12
  ret void

; <label>:10                                      ; preds = %entry
  %11 = getelementptr inbounds %C, %C* %7, i64 0, i32 0
  tail call void @bar(%struct.S* %11)
  br label %9

; <label>:12                                      ; preds = %entry
  %13 = tail call i64 %5(%C* %0)
  br label %9
; CHECK-LABEL: @test4(
; CHECK-NOT: select
; CHECK: or
; CHECK-NOT: select
}

define void @test5(%C*, i1) {
entry:
  %2 = select i1 %1, %C* null, %C* %0
  %3 = icmp ne %C* %2, null
  br i1 %3, label %5, label %7

; <label>:4                                       ; preds = %10, %12
  ret void

; <label>:5                                      ; preds = %entry
  %6 = getelementptr inbounds %C, %C* %2, i64 0, i32 0
  tail call void @bar(%struct.S* %6)
  br label %4

; <label>:7                                      ; preds = %entry
  tail call void @foobar()
  br label %4
; CHECK-LABEL: @test5(
; CHECK-NOT: select
; CHECK: or
; CHECK-NOT: select
}<commit_msg>[InstCombine] use -instnamer and auto-generate complete checks; NFC<commit_after>; NOTE: Assertions have been autogenerated by utils/update_test_checks.py
; Replace a 'select' with 'or' in 'select - cmp [eq|ne] - br' sequence
; RUN: opt -instcombine -S < %s | FileCheck %s

%struct.S = type { i64*, i32, i32 }
%C = type <{ %struct.S }>

declare void @bar(%struct.S*)
declare void @foobar()

define void @test1(%C* %arg) {
; CHECK-LABEL: @test1(
; CHECK-NEXT:  entry:
; CHECK-NEXT:    [[TMP:%.*]] = getelementptr inbounds [[C:%.*]], %C* [[ARG:%.*]], i64 0, i32 0, i32 0
; CHECK-NEXT:    [[M:%.*]] = load i64*, i64** [[TMP]], align 8
; CHECK-NEXT:    [[TMP1:%.*]] = getelementptr inbounds [[C]], %C* [[ARG]], i64 1, i32 0, i32 0
; CHECK-NEXT:    [[N:%.*]] = load i64*, i64** [[TMP1]], align 8
; CHECK-NEXT:    [[TMP71:%.*]] = icmp eq %C* [[ARG]], null
; CHECK-NEXT:    [[NOT_TMP5:%.*]] = icmp ne i64* [[M]], [[N]]
; CHECK-NEXT:    [[TMP7:%.*]] = or i1 [[TMP71]], [[NOT_TMP5]]
; CHECK-NEXT:    br i1 [[TMP7]], label [[BB10:%.*]], label [[BB8:%.*]]
; CHECK:       bb:
; CHECK-NEXT:    ret void
; CHECK:       bb8:
; CHECK-NEXT:    [[TMP9:%.*]] = getelementptr inbounds [[C]], %C* [[ARG]], i64 0, i32 0
; CHECK-NEXT:    tail call void @bar(%struct.S* [[TMP9]])
; CHECK-NEXT:    br label [[BB:%.*]]
; CHECK:       bb10:
; CHECK-NEXT:    [[TMP2:%.*]] = getelementptr inbounds i64, i64* [[M]], i64 9
; CHECK-NEXT:    [[TMP3:%.*]] = bitcast i64* [[TMP2]] to i64 (%C*)**
; CHECK-NEXT:    [[TMP4:%.*]] = load i64 (%C*)*, i64 (%C*)** [[TMP3]], align 8
; CHECK-NEXT:    [[TMP11:%.*]] = tail call i64 [[TMP4]](%C* [[ARG]])
; CHECK-NEXT:    br label [[BB]]
;
entry:
  %tmp = getelementptr inbounds %C, %C* %arg, i64 0, i32 0, i32 0
  %m = load i64*, i64** %tmp, align 8
  %tmp1 = getelementptr inbounds %C, %C* %arg, i64 1, i32 0, i32 0
  %n = load i64*, i64** %tmp1, align 8
  %tmp2 = getelementptr inbounds i64, i64* %m, i64 9
  %tmp3 = bitcast i64* %tmp2 to i64 (%C*)**
  %tmp4 = load i64 (%C*)*, i64 (%C*)** %tmp3, align 8
  %tmp5 = icmp eq i64* %m, %n
  %tmp6 = select i1 %tmp5, %C* %arg, %C* null
  %tmp7 = icmp eq %C* %tmp6, null
  br i1 %tmp7, label %bb10, label %bb8

bb:                                               ; preds = %bb10, %bb8
  ret void

bb8:                                              ; preds = %entry
  %tmp9 = getelementptr inbounds %C, %C* %tmp6, i64 0, i32 0
  tail call void @bar(%struct.S* %tmp9)
  br label %bb

bb10:                                             ; preds = %entry
  %tmp11 = tail call i64 %tmp4(%C* %arg)
  br label %bb
}

define void @test2(%C* %arg) {
; CHECK-LABEL: @test2(
; CHECK-NEXT:  entry:
; CHECK-NEXT:    [[TMP:%.*]] = getelementptr inbounds [[C:%.*]], %C* [[ARG:%.*]], i64 0, i32 0, i32 0
; CHECK-NEXT:    [[M:%.*]] = load i64*, i64** [[TMP]], align 8
; CHECK-NEXT:    [[TMP1:%.*]] = getelementptr inbounds [[C]], %C* [[ARG]], i64 1, i32 0, i32 0
; CHECK-NEXT:    [[N:%.*]] = load i64*, i64** [[TMP1]], align 8
; CHECK-NEXT:    [[TMP5:%.*]] = icmp eq i64* [[M]], [[N]]
; CHECK-NEXT:    [[TMP71:%.*]] = icmp eq %C* [[ARG]], null
; CHECK-NEXT:    [[TMP7:%.*]] = or i1 [[TMP5]], [[TMP71]]
; CHECK-NEXT:    br i1 [[TMP7]], label [[BB10:%.*]], label [[BB8:%.*]]
; CHECK:       bb:
; CHECK-NEXT:    ret void
; CHECK:       bb8:
; CHECK-NEXT:    [[TMP9:%.*]] = getelementptr inbounds [[C]], %C* [[ARG]], i64 0, i32 0
; CHECK-NEXT:    tail call void @bar(%struct.S* [[TMP9]])
; CHECK-NEXT:    br label [[BB:%.*]]
; CHECK:       bb10:
; CHECK-NEXT:    [[TMP2:%.*]] = getelementptr inbounds i64, i64* [[M]], i64 9
; CHECK-NEXT:    [[TMP3:%.*]] = bitcast i64* [[TMP2]] to i64 (%C*)**
; CHECK-NEXT:    [[TMP4:%.*]] = load i64 (%C*)*, i64 (%C*)** [[TMP3]], align 8
; CHECK-NEXT:    [[TMP11:%.*]] = tail call i64 [[TMP4]](%C* [[ARG]])
; CHECK-NEXT:    br label [[BB]]
;
entry:
  %tmp = getelementptr inbounds %C, %C* %arg, i64 0, i32 0, i32 0
  %m = load i64*, i64** %tmp, align 8
  %tmp1 = getelementptr inbounds %C, %C* %arg, i64 1, i32 0, i32 0
  %n = load i64*, i64** %tmp1, align 8
  %tmp2 = getelementptr inbounds i64, i64* %m, i64 9
  %tmp3 = bitcast i64* %tmp2 to i64 (%C*)**
  %tmp4 = load i64 (%C*)*, i64 (%C*)** %tmp3, align 8
  %tmp5 = icmp eq i64* %m, %n
  %tmp6 = select i1 %tmp5, %C* null, %C* %arg
  %tmp7 = icmp eq %C* %tmp6, null
  br i1 %tmp7, label %bb10, label %bb8

bb:                                               ; preds = %bb10, %bb8
  ret void

bb8:                                              ; preds = %entry
  %tmp9 = getelementptr inbounds %C, %C* %tmp6, i64 0, i32 0
  tail call void @bar(%struct.S* %tmp9)
  br label %bb

bb10:                                             ; preds = %entry
  %tmp11 = tail call i64 %tmp4(%C* %arg)
  br label %bb
}

define void @test3(%C* %arg) {
; CHECK-LABEL: @test3(
; CHECK-NEXT:  entry:
; CHECK-NEXT:    [[TMP:%.*]] = getelementptr inbounds [[C:%.*]], %C* [[ARG:%.*]], i64 0, i32 0, i32 0
; CHECK-NEXT:    [[M:%.*]] = load i64*, i64** [[TMP]], align 8
; CHECK-NEXT:    [[TMP1:%.*]] = getelementptr inbounds [[C]], %C* [[ARG]], i64 1, i32 0, i32 0
; CHECK-NEXT:    [[N:%.*]] = load i64*, i64** [[TMP1]], align 8
; CHECK-NEXT:    [[TMP71:%.*]] = icmp eq %C* [[ARG]], null
; CHECK-NEXT:    [[NOT_TMP5:%.*]] = icmp ne i64* [[M]], [[N]]
; CHECK-NEXT:    [[TMP7:%.*]] = or i1 [[TMP71]], [[NOT_TMP5]]
; CHECK-NEXT:    br i1 [[TMP7]], label [[BB10:%.*]], label [[BB8:%.*]]
; CHECK:       bb:
; CHECK-NEXT:    ret void
; CHECK:       bb8:
; CHECK-NEXT:    [[TMP9:%.*]] = getelementptr inbounds [[C]], %C* [[ARG]], i64 0, i32 0
; CHECK-NEXT:    tail call void @bar(%struct.S* [[TMP9]])
; CHECK-NEXT:    br label [[BB:%.*]]
; CHECK:       bb10:
; CHECK-NEXT:    [[TMP2:%.*]] = getelementptr inbounds i64, i64* [[M]], i64 9
; CHECK-NEXT:    [[TMP3:%.*]] = bitcast i64* [[TMP2]] to i64 (%C*)**
; CHECK-NEXT:    [[TMP4:%.*]] = load i64 (%C*)*, i64 (%C*)** [[TMP3]], align 8
; CHECK-NEXT:    [[TMP11:%.*]] = tail call i64 [[TMP4]](%C* [[ARG]])
; CHECK-NEXT:    br label [[BB]]
;
entry:
  %tmp = getelementptr inbounds %C, %C* %arg, i64 0, i32 0, i32 0
  %m = load i64*, i64** %tmp, align 8
  %tmp1 = getelementptr inbounds %C, %C* %arg, i64 1, i32 0, i32 0
  %n = load i64*, i64** %tmp1, align 8
  %tmp2 = getelementptr inbounds i64, i64* %m, i64 9
  %tmp3 = bitcast i64* %tmp2 to i64 (%C*)**
  %tmp4 = load i64 (%C*)*, i64 (%C*)** %tmp3, align 8
  %tmp5 = icmp eq i64* %m, %n
  %tmp6 = select i1 %tmp5, %C* %arg, %C* null
  %tmp7 = icmp ne %C* %tmp6, null
  br i1 %tmp7, label %bb8, label %bb10

bb:                                               ; preds = %bb10, %bb8
  ret void

bb8:                                              ; preds = %entry
  %tmp9 = getelementptr inbounds %C, %C* %tmp6, i64 0, i32 0
  tail call void @bar(%struct.S* %tmp9)
  br label %bb

bb10:                                             ; preds = %entry
  %tmp11 = tail call i64 %tmp4(%C* %arg)
  br label %bb
}

define void @test4(%C* %arg) {
; CHECK-LABEL: @test4(
; CHECK-NEXT:  entry:
; CHECK-NEXT:    [[TMP:%.*]] = getelementptr inbounds [[C:%.*]], %C* [[ARG:%.*]], i64 0, i32 0, i32 0
; CHECK-NEXT:    [[M:%.*]] = load i64*, i64** [[TMP]], align 8
; CHECK-NEXT:    [[TMP1:%.*]] = getelementptr inbounds [[C]], %C* [[ARG]], i64 1, i32 0, i32 0
; CHECK-NEXT:    [[N:%.*]] = load i64*, i64** [[TMP1]], align 8
; CHECK-NEXT:    [[TMP5:%.*]] = icmp eq i64* [[M]], [[N]]
; CHECK-NEXT:    [[TMP71:%.*]] = icmp eq %C* [[ARG]], null
; CHECK-NEXT:    [[TMP7:%.*]] = or i1 [[TMP5]], [[TMP71]]
; CHECK-NEXT:    br i1 [[TMP7]], label [[BB10:%.*]], label [[BB8:%.*]]
; CHECK:       bb:
; CHECK-NEXT:    ret void
; CHECK:       bb8:
; CHECK-NEXT:    [[TMP9:%.*]] = getelementptr inbounds [[C]], %C* [[ARG]], i64 0, i32 0
; CHECK-NEXT:    tail call void @bar(%struct.S* [[TMP9]])
; CHECK-NEXT:    br label [[BB:%.*]]
; CHECK:       bb10:
; CHECK-NEXT:    [[TMP2:%.*]] = getelementptr inbounds i64, i64* [[M]], i64 9
; CHECK-NEXT:    [[TMP3:%.*]] = bitcast i64* [[TMP2]] to i64 (%C*)**
; CHECK-NEXT:    [[TMP4:%.*]] = load i64 (%C*)*, i64 (%C*)** [[TMP3]], align 8
; CHECK-NEXT:    [[TMP11:%.*]] = tail call i64 [[TMP4]](%C* [[ARG]])
; CHECK-NEXT:    br label [[BB]]
;
entry:
  %tmp = getelementptr inbounds %C, %C* %arg, i64 0, i32 0, i32 0
  %m = load i64*, i64** %tmp, align 8
  %tmp1 = getelementptr inbounds %C, %C* %arg, i64 1, i32 0, i32 0
  %n = load i64*, i64** %tmp1, align 8
  %tmp2 = getelementptr inbounds i64, i64* %m, i64 9
  %tmp3 = bitcast i64* %tmp2 to i64 (%C*)**
  %tmp4 = load i64 (%C*)*, i64 (%C*)** %tmp3, align 8
  %tmp5 = icmp eq i64* %m, %n
  %tmp6 = select i1 %tmp5, %C* null, %C* %arg
  %tmp7 = icmp ne %C* %tmp6, null
  br i1 %tmp7, label %bb8, label %bb10

bb:                                               ; preds = %bb10, %bb8
  ret void

bb8:                                              ; preds = %entry
  %tmp9 = getelementptr inbounds %C, %C* %tmp6, i64 0, i32 0
  tail call void @bar(%struct.S* %tmp9)
  br label %bb

bb10:                                             ; preds = %entry
  %tmp11 = tail call i64 %tmp4(%C* %arg)
  br label %bb
}

define void @test5(%C* %arg, i1 %arg1) {
; CHECK-LABEL: @test5(
; CHECK-NEXT:  entry:
; CHECK-NEXT:    [[TMP21:%.*]] = icmp eq %C* [[ARG:%.*]], null
; CHECK-NEXT:    [[TMP2:%.*]] = or i1 [[TMP21]], [[ARG1:%.*]]
; CHECK-NEXT:    br i1 [[TMP2]], label [[BB5:%.*]], label [[BB3:%.*]]
; CHECK:       bb:
; CHECK-NEXT:    ret void
; CHECK:       bb3:
; CHECK-NEXT:    [[TMP4:%.*]] = getelementptr inbounds [[C:%.*]], %C* [[ARG]], i64 0, i32 0
; CHECK-NEXT:    tail call void @bar(%struct.S* [[TMP4]])
; CHECK-NEXT:    br label [[BB:%.*]]
; CHECK:       bb5:
; CHECK-NEXT:    tail call void @foobar()
; CHECK-NEXT:    br label [[BB]]
;
entry:
  %tmp = select i1 %arg1, %C* null, %C* %arg
  %tmp2 = icmp ne %C* %tmp, null
  br i1 %tmp2, label %bb3, label %bb5

bb:                                               ; preds = %bb5, %bb3
  ret void

bb3:                                              ; preds = %entry
  %tmp4 = getelementptr inbounds %C, %C* %tmp, i64 0, i32 0
  tail call void @bar(%struct.S* %tmp4)
  br label %bb

bb5:                                              ; preds = %entry
  tail call void @foobar()
  br label %bb
}

{'fraction_non_alphanumeric': 0.21023765996343693, 'fraction_numerical': 0.07854289389938385, 'mean_word_length': 2.3072100313479624, 'pattern_counts': {'":': 0, '<': 22, '<?xml version=': 0, '>': 20, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 58, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '924358', 'n_tokens_mistral': 6318, 'n_tokens_neox': 6032, 'n_words': 1941}