reference, declarationdefinition
definition → references, declarations, derived classes, virtual overrides
reference to multiple definitions → definitions
unreferenced
    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
; NOTE: Assertions have been autogenerated by utils/update_test_checks.py
; RUN: opt < %s -instcombine -S | FileCheck %s

define i32 @uaddo_commute1(i32 %x, i32 %y, i32 %z) {
; CHECK-LABEL: @uaddo_commute1(
; CHECK-NEXT:    [[NOTY:%.*]] = xor i32 [[Y:%.*]], -1
; CHECK-NEXT:    [[A:%.*]] = add i32 [[X:%.*]], [[Y]]
; CHECK-NEXT:    [[C:%.*]] = icmp ult i32 [[NOTY]], [[X]]
; CHECK-NEXT:    [[R:%.*]] = select i1 [[C]], i32 [[Z:%.*]], i32 [[A]]
; CHECK-NEXT:    ret i32 [[R]]
;
  %noty = xor i32 %y, -1
  %a = add i32 %x, %y
  %c = icmp ugt i32 %x, %noty
  %r = select i1 %c, i32 %z, i32 %a
  ret i32 %r
}

define <2 x i32> @uaddo_commute2(<2 x i32> %x, <2 x i32> %y, <2 x i32> %z) {
; CHECK-LABEL: @uaddo_commute2(
; CHECK-NEXT:    [[NOTY:%.*]] = xor <2 x i32> [[Y:%.*]], <i32 -1, i32 -1>
; CHECK-NEXT:    [[A:%.*]] = add <2 x i32> [[Y]], [[X:%.*]]
; CHECK-NEXT:    [[C:%.*]] = icmp ult <2 x i32> [[NOTY]], [[X]]
; CHECK-NEXT:    [[R:%.*]] = select <2 x i1> [[C]], <2 x i32> [[Z:%.*]], <2 x i32> [[A]]
; CHECK-NEXT:    ret <2 x i32> [[R]]
;
  %noty = xor <2 x i32> %y, <i32 -1, i32 -1>
  %a = add <2 x i32> %y, %x
  %c = icmp ugt <2 x i32> %x, %noty
  %r = select <2 x i1> %c, <2 x i32> %z, <2 x i32> %a
  ret <2 x i32> %r
}

define i32 @uaddo_commute3(i32 %x, i32 %y, i32 %z) {
; CHECK-LABEL: @uaddo_commute3(
; CHECK-NEXT:    [[NOTY:%.*]] = xor i32 [[Y:%.*]], -1
; CHECK-NEXT:    [[A:%.*]] = add i32 [[X:%.*]], [[Y]]
; CHECK-NEXT:    [[C:%.*]] = icmp ult i32 [[NOTY]], [[X]]
; CHECK-NEXT:    [[R:%.*]] = select i1 [[C]], i32 [[Z:%.*]], i32 [[A]]
; CHECK-NEXT:    ret i32 [[R]]
;
  %noty = xor i32 %y, -1
  %a = add i32 %x, %y
  %c = icmp ult i32 %noty, %x
  %r = select i1 %c, i32 %z, i32 %a
  ret i32 %r
}

define i32 @uaddo_commute4(i32 %x, i32 %y, i32 %z) {
; CHECK-LABEL: @uaddo_commute4(
; CHECK-NEXT:    [[NOTY:%.*]] = xor i32 [[Y:%.*]], -1
; CHECK-NEXT:    [[A:%.*]] = add i32 [[Y]], [[X:%.*]]
; CHECK-NEXT:    [[C:%.*]] = icmp ult i32 [[NOTY]], [[X]]
; CHECK-NEXT:    [[R:%.*]] = select i1 [[C]], i32 [[Z:%.*]], i32 [[A]]
; CHECK-NEXT:    ret i32 [[R]]
;
  %noty = xor i32 %y, -1
  %a = add i32 %y, %x
  %c = icmp ult i32 %noty, %x
  %r = select i1 %c, i32 %z, i32 %a
  ret i32 %r
}

define i32 @uaddo_commute5(i32 %x, i32 %y, i32 %z) {
; CHECK-LABEL: @uaddo_commute5(
; CHECK-NEXT:    [[NOTY:%.*]] = xor i32 [[Y:%.*]], -1
; CHECK-NEXT:    [[A:%.*]] = add i32 [[X:%.*]], [[Y]]
; CHECK-NEXT:    [[C:%.*]] = icmp ult i32 [[NOTY]], [[X]]
; CHECK-NEXT:    [[R:%.*]] = select i1 [[C]], i32 [[A]], i32 [[Z:%.*]]
; CHECK-NEXT:    ret i32 [[R]]
;
  %noty = xor i32 %y, -1
  %a = add i32 %x, %y
  %c = icmp ugt i32 %x, %noty
  %r = select i1 %c, i32 %a, i32 %z
  ret i32 %r
}

define i32 @uaddo_commute6(i32 %x, i32 %y, i32 %z) {
; CHECK-LABEL: @uaddo_commute6(
; CHECK-NEXT:    [[NOTY:%.*]] = xor i32 [[Y:%.*]], -1
; CHECK-NEXT:    [[A:%.*]] = add i32 [[Y]], [[X:%.*]]
; CHECK-NEXT:    [[C:%.*]] = icmp ult i32 [[NOTY]], [[X]]
; CHECK-NEXT:    [[R:%.*]] = select i1 [[C]], i32 [[A]], i32 [[Z:%.*]]
; CHECK-NEXT:    ret i32 [[R]]
;
  %noty = xor i32 %y, -1
  %a = add i32 %y, %x
  %c = icmp ugt i32 %x, %noty
  %r = select i1 %c, i32 %a, i32 %z
  ret i32 %r
}

define i32 @uaddo_commute7(i32 %x, i32 %y, i32 %z) {
; CHECK-LABEL: @uaddo_commute7(
; CHECK-NEXT:    [[NOTY:%.*]] = xor i32 [[Y:%.*]], -1
; CHECK-NEXT:    [[A:%.*]] = add i32 [[X:%.*]], [[Y]]
; CHECK-NEXT:    [[C:%.*]] = icmp ult i32 [[NOTY]], [[X]]
; CHECK-NEXT:    [[R:%.*]] = select i1 [[C]], i32 [[A]], i32 [[Z:%.*]]
; CHECK-NEXT:    ret i32 [[R]]
;
  %noty = xor i32 %y, -1
  %a = add i32 %x, %y
  %c = icmp ult i32 %noty, %x
  %r = select i1 %c, i32 %a, i32 %z
  ret i32 %r
}

define i32 @uaddo_commute8(i32 %x, i32 %y, i32 %z) {
; CHECK-LABEL: @uaddo_commute8(
; CHECK-NEXT:    [[NOTY:%.*]] = xor i32 [[Y:%.*]], -1
; CHECK-NEXT:    [[A:%.*]] = add i32 [[Y]], [[X:%.*]]
; CHECK-NEXT:    [[C:%.*]] = icmp ult i32 [[NOTY]], [[X]]
; CHECK-NEXT:    [[R:%.*]] = select i1 [[C]], i32 [[A]], i32 [[Z:%.*]]
; CHECK-NEXT:    ret i32 [[R]]
;
  %noty = xor i32 %y, -1
  %a = add i32 %y, %x
  %c = icmp ult i32 %noty, %x
  %r = select i1 %c, i32 %a, i32 %z
  ret i32 %r
}

define i32 @uaddo_wrong_pred1(i32 %x, i32 %y, i32 %z) {
; CHECK-LABEL: @uaddo_wrong_pred1(
; CHECK-NEXT:    [[NOTY:%.*]] = xor i32 [[Y:%.*]], -1
; CHECK-NEXT:    [[A:%.*]] = add i32 [[X:%.*]], [[Y]]
; CHECK-NEXT:    [[C:%.*]] = icmp ugt i32 [[NOTY]], [[X]]
; CHECK-NEXT:    [[R:%.*]] = select i1 [[C]], i32 [[Z:%.*]], i32 [[A]]
; CHECK-NEXT:    ret i32 [[R]]
;
  %noty = xor i32 %y, -1
  %a = add i32 %x, %y
  %c = icmp ult i32 %x, %noty
  %r = select i1 %c, i32 %z, i32 %a
  ret i32 %r
}

define i32 @uaddo_wrong_pred2(i32 %x, i32 %y, i32 %z) {
; CHECK-LABEL: @uaddo_wrong_pred2(
; CHECK-NEXT:    [[NOTY:%.*]] = xor i32 [[Y:%.*]], -1
; CHECK-NEXT:    [[A:%.*]] = add i32 [[X:%.*]], [[Y]]
; CHECK-NEXT:    [[C:%.*]] = icmp ugt i32 [[NOTY]], [[X]]
; CHECK-NEXT:    [[R:%.*]] = select i1 [[C]], i32 [[A]], i32 [[Z:%.*]]
; CHECK-NEXT:    ret i32 [[R]]
;
  %noty = xor i32 %y, -1
  %a = add i32 %x, %y
  %c = icmp uge i32 %x, %noty
  %r = select i1 %c, i32 %z, i32 %a
  ret i32 %r
}

; icmp canonicalization should be consistent for these cases.
; Either the compare depends on the sum or not.

define i1 @uaddo_1(i8 %x, i8* %p) {
; CHECK-LABEL: @uaddo_1(
; CHECK-NEXT:    [[A:%.*]] = add i8 [[X:%.*]], 1
; CHECK-NEXT:    store i8 [[A]], i8* [[P:%.*]], align 1
; CHECK-NEXT:    [[C:%.*]] = icmp eq i8 [[A]], 0
; CHECK-NEXT:    ret i1 [[C]]
;
  %a = add i8 %x, 1
  store i8 %a, i8* %p
  %c = icmp ult i8 %a, 1
  ret i1 %c
}

define i1 @uaddo_neg1(i8 %x, i8* %p) {
; CHECK-LABEL: @uaddo_neg1(
; CHECK-NEXT:    [[A:%.*]] = add i8 [[X:%.*]], -1
; CHECK-NEXT:    store i8 [[A]], i8* [[P:%.*]], align 1
; CHECK-NEXT:    [[C:%.*]] = icmp ne i8 [[X]], 0
; CHECK-NEXT:    ret i1 [[C]]
;
  %a = add i8 %x, -1
  store i8 %a, i8* %p
  %c = icmp ne i8 %a, -1
  ret i1 %c
}