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
; NOTE: Assertions have been autogenerated by utils/update_test_checks.py
; RUN: opt -instcombine -S < %s | FileCheck %s

define i32 @shl_sub_i32(i32 %x) {
; CHECK-LABEL: @shl_sub_i32(
; CHECK-NEXT:    [[R:%.*]] = lshr i32 -2147483648, [[X:%.*]]
; CHECK-NEXT:    ret i32 [[R]]
;
  %s = sub i32 31, %x
  %r = shl i32 1, %s
  ret i32 %r
}

define i32 @shl_sub_multiuse_i32(i32 %x) {
; CHECK-LABEL: @shl_sub_multiuse_i32(
; CHECK-NEXT:    [[S:%.*]] = sub i32 31, [[X:%.*]]
; CHECK-NEXT:    call void @use(i32 [[S]])
; CHECK-NEXT:    [[R:%.*]] = lshr i32 -2147483648, [[X]]
; CHECK-NEXT:    ret i32 [[R]]
;
  %s = sub i32 31, %x
  call void @use(i32 %s)
  %r = shl i32 1, %s
  ret i32 %r
}

define i8 @shl_sub_i8(i8 %x) {
; CHECK-LABEL: @shl_sub_i8(
; CHECK-NEXT:    [[R:%.*]] = lshr i8 -128, [[X:%.*]]
; CHECK-NEXT:    ret i8 [[R]]
;
  %s = sub i8 7, %x
  %r = shl i8 1, %s
  ret i8 %r
}

define i64 @shl_sub_i64(i64 %x) {
; CHECK-LABEL: @shl_sub_i64(
; CHECK-NEXT:    [[R:%.*]] = lshr i64 -9223372036854775808, [[X:%.*]]
; CHECK-NEXT:    ret i64 [[R]]
;
  %s = sub i64 63, %x
  %r = shl i64 1, %s
  ret i64 %r
}

define <2 x i64> @shl_sub_i64_vec(<2 x i64> %x) {
; CHECK-LABEL: @shl_sub_i64_vec(
; CHECK-NEXT:    [[R:%.*]] = lshr <2 x i64> <i64 -9223372036854775808, i64 -9223372036854775808>, [[X:%.*]]
; CHECK-NEXT:    ret <2 x i64> [[R]]
;
  %s = sub <2 x i64> <i64 63, i64 63>, %x
  %r = shl <2 x i64> <i64 1, i64 1>, %s
  ret <2 x i64> %r
}

define <3 x i64> @shl_sub_i64_vec_undef(<3 x i64> %x) {
; CHECK-LABEL: @shl_sub_i64_vec_undef(
; CHECK-NEXT:    [[R:%.*]] = lshr <3 x i64> <i64 -9223372036854775808, i64 -9223372036854775808, i64 -9223372036854775808>, [[X:%.*]]
; CHECK-NEXT:    ret <3 x i64> [[R]]
;
  %s = sub <3 x i64> <i64 63, i64 63, i64 63>, %x
  %r = shl <3 x i64> <i64 1, i64 undef, i64 1>, %s
  ret <3 x i64> %r
}

; Negative tests

define i32 @shl_bad_sub_i32(i32 %x) {
; CHECK-LABEL: @shl_bad_sub_i32(
; CHECK-NEXT:    [[S:%.*]] = sub i32 32, [[X:%.*]]
; CHECK-NEXT:    [[R:%.*]] = shl i32 1, [[S]]
; CHECK-NEXT:    ret i32 [[R]]
;
  %s = sub i32 32, %x
  %r = shl i32 1, %s
  ret i32 %r
}

define i32 @bad_shl_sub_i32(i32 %x) {
; CHECK-LABEL: @bad_shl_sub_i32(
; CHECK-NEXT:    [[S:%.*]] = sub i32 31, [[X:%.*]]
; CHECK-NEXT:    [[R:%.*]] = shl i32 2, [[S]]
; CHECK-NEXT:    ret i32 [[R]]
;
  %s = sub i32 31, %x
  %r = shl i32 2, %s
  ret i32 %r
}

define i32 @shl_bad_sub2_i32(i32 %x) {
; CHECK-LABEL: @shl_bad_sub2_i32(
; CHECK-NEXT:    [[S:%.*]] = add i32 [[X:%.*]], -31
; CHECK-NEXT:    [[R:%.*]] = shl i32 1, [[S]]
; CHECK-NEXT:    ret i32 [[R]]
;
  %s = sub i32 %x, 31
  %r = shl i32 1, %s
  ret i32 %r
}

define i32 @bad_shl2_sub_i32(i32 %x) {
; CHECK-LABEL: @bad_shl2_sub_i32(
; CHECK-NEXT:    [[S:%.*]] = add i32 [[X:%.*]], -31
; CHECK-NEXT:    [[R:%.*]] = shl i32 1, [[S]]
; CHECK-NEXT:    ret i32 [[R]]
;
  %s = sub i32 %x, 31
  %r = shl i32 1, %s
  ret i32 %r
}

define i8 @shl_bad_sub_i8(i8 %x) {
; CHECK-LABEL: @shl_bad_sub_i8(
; CHECK-NEXT:    [[S:%.*]] = sub i8 4, [[X:%.*]]
; CHECK-NEXT:    [[R:%.*]] = shl i8 1, [[S]]
; CHECK-NEXT:    ret i8 [[R]]
;
  %s = sub i8 4, %x
  %r = shl i8 1, %s
  ret i8 %r
}

define i64 @shl_bad_sub_i64(i64 %x) {
; CHECK-LABEL: @shl_bad_sub_i64(
; CHECK-NEXT:    [[S:%.*]] = sub i64 67, [[X:%.*]]
; CHECK-NEXT:    [[R:%.*]] = shl i64 1, [[S]]
; CHECK-NEXT:    ret i64 [[R]]
;
  %s = sub i64 67, %x
  %r = shl i64 1, %s
  ret i64 %r
}

define <2 x i64> @shl_bad_sub_i64_vec(<2 x i64> %x) {
; CHECK-LABEL: @shl_bad_sub_i64_vec(
; CHECK-NEXT:    [[S:%.*]] = sub <2 x i64> <i64 53, i64 53>, [[X:%.*]]
; CHECK-NEXT:    [[R:%.*]] = shl <2 x i64> <i64 1, i64 1>, [[S]]
; CHECK-NEXT:    ret <2 x i64> [[R]]
;
  %s = sub <2 x i64> <i64 53, i64 53>, %x
  %r = shl <2 x i64> <i64 1, i64 1>, %s
  ret <2 x i64> %r
}

define <2 x i64> @bad_shl_sub_i64_vec(<2 x i64> %x) {
; CHECK-LABEL: @bad_shl_sub_i64_vec(
; CHECK-NEXT:    [[S:%.*]] = sub <2 x i64> <i64 63, i64 63>, [[X:%.*]]
; CHECK-NEXT:    [[R:%.*]] = shl <2 x i64> <i64 2, i64 2>, [[S]]
; CHECK-NEXT:    ret <2 x i64> [[R]]
;
  %s = sub <2 x i64> <i64 63, i64 63>, %x
  %r = shl <2 x i64> <i64 2, i64 2>, %s
  ret <2 x i64> %r
}

define <3 x i64> @shl_sub_i64_vec_undef_bad(<3 x i64> %x) {
; CHECK-LABEL: @shl_sub_i64_vec_undef_bad(
; CHECK-NEXT:    [[S:%.*]] = sub <3 x i64> <i64 63, i64 undef, i64 63>, [[X:%.*]]
; CHECK-NEXT:    [[R:%.*]] = shl <3 x i64> <i64 1, i64 1, i64 1>, [[S]]
; CHECK-NEXT:    ret <3 x i64> [[R]]
;
  %s = sub <3 x i64> <i64 63, i64 undef, i64 63>, %x
  %r = shl <3 x i64> <i64 1, i64 1, i64 1>, %s
  ret <3 x i64> %r
}

define <3 x i64> @shl_sub_i64_vec_undef_bad2(<3 x i64> %x) {
; CHECK-LABEL: @shl_sub_i64_vec_undef_bad2(
; CHECK-NEXT:    [[S:%.*]] = sub <3 x i64> <i64 63, i64 undef, i64 63>, [[X:%.*]]
; CHECK-NEXT:    [[R:%.*]] = shl <3 x i64> <i64 1, i64 undef, i64 1>, [[S]]
; CHECK-NEXT:    ret <3 x i64> [[R]]
;
  %s = sub <3 x i64> <i64 63, i64 undef, i64 63>, %x
  %r = shl <3 x i64> <i64 1, i64 undef, i64 1>, %s
  ret <3 x i64> %r
}


declare void @use(i32)