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
  183
  184
  185
  186
  187
  188
  189
  190
  191
  192
  193
  194
  195
  196
  197
  198
  199
  200
  201
  202
  203
  204
  205
  206
  207
  208
  209
  210
  211
  212
  213
  214
  215
  216
  217
  218
  219
  220
  221
  222
  223
  224
  225
  226
  227
  228
  229
  230
  231
  232
  233
  234
  235
  236
  237
  238
  239
  240
  241
  242
  243
  244
  245
  246
  247
  248
  249
  250
  251
  252
  253
  254
  255
  256
  257
  258
  259
  260
  261
  262
  263
  264
  265
  266
  267
  268
  269
  270
; NOTE: Assertions have been autogenerated by utils/update_test_checks.py
; RUN: opt < %s -aggressive-instcombine -S | FileCheck %s
; RUN: opt < %s -passes=aggressive-instcombine -S | FileCheck %s
target datalayout = "e-p:64:64:64-i1:8:8-i8:8:8-i16:16:16-i32:32:32-i64:64:64-f32:32:32-f64:64:64-v64:64:64-v128:128:128-a0:0:64-s0:64:64-f80:128:128-n8:16:32:64"

; Aggressive Instcombine should be able to reduce width of these expressions.

declare i32 @use32(i32)
declare i32 @use64(i64)
declare <2 x i32> @use32_vec(<2 x i32>)
declare <2 x i32> @use64_vec(<2 x i64>)

;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
;; These tests check cases where expression dag post-dominated by TruncInst
;; contains instruction, which has more than one usage.
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;

define void @multi_uses_add(i32 %X) {
; CHECK-LABEL: @multi_uses_add(
; CHECK-NEXT:    [[A1:%.*]] = zext i32 [[X:%.*]] to i64
; CHECK-NEXT:    [[B1:%.*]] = add i32 [[X]], 15
; CHECK-NEXT:    [[C1:%.*]] = mul i32 [[B1]], [[B1]]
; CHECK-NEXT:    [[TMP1:%.*]] = call i32 @use32(i32 [[C1]])
; CHECK-NEXT:    [[TMP2:%.*]] = call i32 @use64(i64 [[A1]])
; CHECK-NEXT:    ret void
;
  %A1 = zext i32 %X to i64
  %B1 = add i64 %A1, 15
  %C1 = mul i64 %B1, %B1
  %T1 = trunc i64 %C1 to i32
  call i32 @use32(i32 %T1)
  ; make sure zext have another use that is not post-dominated by the TruncInst.
  call i32 @use64(i64 %A1)
  ret void
}

define void @multi_uses_or(i32 %X) {
; CHECK-LABEL: @multi_uses_or(
; CHECK-NEXT:    [[A1:%.*]] = zext i32 [[X:%.*]] to i64
; CHECK-NEXT:    [[B1:%.*]] = or i32 [[X]], 15
; CHECK-NEXT:    [[C1:%.*]] = mul i32 [[B1]], [[B1]]
; CHECK-NEXT:    [[TMP1:%.*]] = call i32 @use32(i32 [[C1]])
; CHECK-NEXT:    [[TMP2:%.*]] = call i32 @use64(i64 [[A1]])
; CHECK-NEXT:    ret void
;
  %A1 = zext i32 %X to i64
  %B1 = or i64 %A1, 15
  %C1 = mul i64 %B1, %B1
  %T1 = trunc i64 %C1 to i32
  call i32 @use32(i32 %T1)
  ; make sure zext have another use that is not post-dominated by the TruncInst.
  call i32 @use64(i64 %A1)
  ret void
}

define void @multi_uses_xor(i32 %X) {
; CHECK-LABEL: @multi_uses_xor(
; CHECK-NEXT:    [[A1:%.*]] = zext i32 [[X:%.*]] to i64
; CHECK-NEXT:    [[B1:%.*]] = xor i32 [[X]], 15
; CHECK-NEXT:    [[C1:%.*]] = mul i32 [[B1]], [[B1]]
; CHECK-NEXT:    [[TMP1:%.*]] = call i32 @use32(i32 [[C1]])
; CHECK-NEXT:    [[TMP2:%.*]] = call i32 @use64(i64 [[A1]])
; CHECK-NEXT:    ret void
;
  %A1 = zext i32 %X to i64
  %B1 = xor i64 %A1, 15
  %C1 = mul i64 %B1, %B1
  %T1 = trunc i64 %C1 to i32
  call i32 @use32(i32 %T1)
  ; make sure zext have another use that is not post-dominated by the TruncInst.
  call i32 @use64(i64 %A1)
  ret void
}

define void @multi_uses_and(i32 %X) {
; CHECK-LABEL: @multi_uses_and(
; CHECK-NEXT:    [[A1:%.*]] = zext i32 [[X:%.*]] to i64
; CHECK-NEXT:    [[B1:%.*]] = and i32 [[X]], 15
; CHECK-NEXT:    [[C1:%.*]] = mul i32 [[B1]], [[B1]]
; CHECK-NEXT:    [[TMP1:%.*]] = call i32 @use32(i32 [[C1]])
; CHECK-NEXT:    [[TMP2:%.*]] = call i32 @use64(i64 [[A1]])
; CHECK-NEXT:    ret void
;
  %A1 = zext i32 %X to i64
  %B1 = and i64 %A1, 15
  %C1 = mul i64 %B1, %B1
  %T1 = trunc i64 %C1 to i32
  call i32 @use32(i32 %T1)
  ; make sure zext have another use that is not post-dominated by the TruncInst.
  call i32 @use64(i64 %A1)
  ret void
}

define void @multi_uses_sub(i32 %X, i32 %Y) {
; CHECK-LABEL: @multi_uses_sub(
; CHECK-NEXT:    [[A1:%.*]] = zext i32 [[X:%.*]] to i64
; CHECK-NEXT:    [[A2:%.*]] = zext i32 [[Y:%.*]] to i64
; CHECK-NEXT:    [[B1:%.*]] = sub i32 [[X]], [[Y]]
; CHECK-NEXT:    [[C1:%.*]] = mul i32 [[B1]], [[B1]]
; CHECK-NEXT:    [[TMP1:%.*]] = call i32 @use32(i32 [[C1]])
; CHECK-NEXT:    [[TMP2:%.*]] = call i32 @use64(i64 [[A1]])
; CHECK-NEXT:    [[TMP3:%.*]] = call i32 @use64(i64 [[A2]])
; CHECK-NEXT:    ret void
;
  %A1 = zext i32 %X to i64
  %A2 = zext i32 %Y to i64
  %B1 = sub i64 %A1, %A2
  %C1 = mul i64 %B1, %B1
  %T1 = trunc i64 %C1 to i32
  call i32 @use32(i32 %T1)
  ; make sure zext have another use that is not post-dominated by the TruncInst.
  call i32 @use64(i64 %A1)
  call i32 @use64(i64 %A2)
  ret void
}

define void @multi_use_vec_add(<2 x i32> %X) {
; CHECK-LABEL: @multi_use_vec_add(
; CHECK-NEXT:    [[A1:%.*]] = zext <2 x i32> [[X:%.*]] to <2 x i64>
; CHECK-NEXT:    [[B1:%.*]] = add <2 x i32> [[X]], <i32 15, i32 15>
; CHECK-NEXT:    [[C1:%.*]] = mul <2 x i32> [[B1]], [[B1]]
; CHECK-NEXT:    [[TMP1:%.*]] = call <2 x i32> @use32_vec(<2 x i32> [[C1]])
; CHECK-NEXT:    [[TMP2:%.*]] = call <2 x i32> @use64_vec(<2 x i64> [[A1]])
; CHECK-NEXT:    ret void
;
  %A1 = zext <2 x i32> %X to <2 x i64>
  %B1 = add <2 x i64> %A1, <i64 15, i64 15>
  %C1 = mul <2 x i64> %B1, %B1
  %T1 = trunc <2 x i64> %C1 to <2 x i32>
  call <2 x i32> @use32_vec(<2 x i32> %T1)
  ; make sure zext have another use that is not post-dominated by the TruncInst.
  call <2 x i32> @use64_vec(<2 x i64> %A1)
  ret void
}

define void @multi_use_vec_or(<2 x i32> %X) {
; CHECK-LABEL: @multi_use_vec_or(
; CHECK-NEXT:    [[A1:%.*]] = zext <2 x i32> [[X:%.*]] to <2 x i64>
; CHECK-NEXT:    [[B1:%.*]] = or <2 x i32> [[X]], <i32 15, i32 15>
; CHECK-NEXT:    [[C1:%.*]] = mul <2 x i32> [[B1]], [[B1]]
; CHECK-NEXT:    [[TMP1:%.*]] = call <2 x i32> @use32_vec(<2 x i32> [[C1]])
; CHECK-NEXT:    [[TMP2:%.*]] = call <2 x i32> @use64_vec(<2 x i64> [[A1]])
; CHECK-NEXT:    ret void
;
  %A1 = zext <2 x i32> %X to <2 x i64>
  %B1 = or <2 x i64> %A1, <i64 15, i64 15>
  %C1 = mul <2 x i64> %B1, %B1
  %T1 = trunc <2 x i64> %C1 to <2 x i32>
  call <2 x i32> @use32_vec(<2 x i32> %T1)
  ; make sure zext have another use that is not post-dominated by the TruncInst.
  call <2 x i32> @use64_vec(<2 x i64> %A1)
  ret void
}

define void @multi_use_vec_xor(<2 x i32> %X) {
; CHECK-LABEL: @multi_use_vec_xor(
; CHECK-NEXT:    [[A1:%.*]] = zext <2 x i32> [[X:%.*]] to <2 x i64>
; CHECK-NEXT:    [[B1:%.*]] = xor <2 x i32> [[X]], <i32 15, i32 15>
; CHECK-NEXT:    [[C1:%.*]] = mul <2 x i32> [[B1]], [[B1]]
; CHECK-NEXT:    [[TMP1:%.*]] = call <2 x i32> @use32_vec(<2 x i32> [[C1]])
; CHECK-NEXT:    [[TMP2:%.*]] = call <2 x i32> @use64_vec(<2 x i64> [[A1]])
; CHECK-NEXT:    ret void
;
  %A1 = zext <2 x i32> %X to <2 x i64>
  %B1 = xor <2 x i64> %A1, <i64 15, i64 15>
  %C1 = mul <2 x i64> %B1, %B1
  %T1 = trunc <2 x i64> %C1 to <2 x i32>
  call <2 x i32> @use32_vec(<2 x i32> %T1)
  ; make sure zext have another use that is not post-dominated by the TruncInst.
  call <2 x i32> @use64_vec(<2 x i64> %A1)
  ret void
}

define void @multi_use_vec_and(<2 x i32> %X) {
; CHECK-LABEL: @multi_use_vec_and(
; CHECK-NEXT:    [[A1:%.*]] = zext <2 x i32> [[X:%.*]] to <2 x i64>
; CHECK-NEXT:    [[B1:%.*]] = and <2 x i32> [[X]], <i32 15, i32 15>
; CHECK-NEXT:    [[C1:%.*]] = mul <2 x i32> [[B1]], [[B1]]
; CHECK-NEXT:    [[TMP1:%.*]] = call <2 x i32> @use32_vec(<2 x i32> [[C1]])
; CHECK-NEXT:    [[TMP2:%.*]] = call <2 x i32> @use64_vec(<2 x i64> [[A1]])
; CHECK-NEXT:    ret void
;
  %A1 = zext <2 x i32> %X to <2 x i64>
  %B1 = and <2 x i64> %A1, <i64 15, i64 15>
  %C1 = mul <2 x i64> %B1, %B1
  %T1 = trunc <2 x i64> %C1 to <2 x i32>
  call <2 x i32> @use32_vec(<2 x i32> %T1)
  ; make sure zext have another use that is not post-dominated by the TruncInst.
  call <2 x i32> @use64_vec(<2 x i64> %A1)
  ret void
}

define void @multi_use_vec_sub(<2 x i32> %X, <2 x i32> %Y) {
; CHECK-LABEL: @multi_use_vec_sub(
; CHECK-NEXT:    [[A1:%.*]] = zext <2 x i32> [[X:%.*]] to <2 x i64>
; CHECK-NEXT:    [[A2:%.*]] = zext <2 x i32> [[Y:%.*]] to <2 x i64>
; CHECK-NEXT:    [[B1:%.*]] = sub <2 x i32> [[X]], [[Y]]
; CHECK-NEXT:    [[C1:%.*]] = mul <2 x i32> [[B1]], [[B1]]
; CHECK-NEXT:    [[TMP1:%.*]] = call <2 x i32> @use32_vec(<2 x i32> [[C1]])
; CHECK-NEXT:    [[TMP2:%.*]] = call <2 x i32> @use64_vec(<2 x i64> [[A1]])
; CHECK-NEXT:    [[TMP3:%.*]] = call <2 x i32> @use64_vec(<2 x i64> [[A2]])
; CHECK-NEXT:    ret void
;
  %A1 = zext <2 x i32> %X to <2 x i64>
  %A2 = zext <2 x i32> %Y to <2 x i64>
  %B1 = sub <2 x i64> %A1, %A2
  %C1 = mul <2 x i64> %B1, %B1
  %T1 = trunc <2 x i64> %C1 to <2 x i32>
  call <2 x i32> @use32_vec(<2 x i32> %T1)
  ; make sure zext have another use that is not post-dominated by the TruncInst.
  call <2 x i32> @use64_vec(<2 x i64> %A1)
  call <2 x i32> @use64_vec(<2 x i64> %A2)
  ret void
}

;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
;; These tests check cases where expression dag post-dominated by TruncInst
;; contains TruncInst leaf or ZEXT/SEXT leafs which turn into TruncInst leaves.
;; Check that both expressions are reduced and no TruncInst remains or (was
;; generated).
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;

; Notice that there are two expression patterns below:
; 1. %T2->%C2->(%B2->(%T1, 15), %B2->(%T1, 15))
; 2. %T1`->%C1->(%B1->(%A1, 15), %B1->(%A1, 15))
;    (where %T1` is the reduced node of %T1 into trunc instruction)
define void @trunc_as_a_leaf(i32 %X) {
; CHECK-LABEL: @trunc_as_a_leaf(
; CHECK-NEXT:    [[B1:%.*]] = add i32 [[X:%.*]], 15
; CHECK-NEXT:    [[C1:%.*]] = mul i32 [[B1]], [[B1]]
; CHECK-NEXT:    [[B2:%.*]] = add i32 [[C1]], 15
; CHECK-NEXT:    [[C2:%.*]] = mul i32 [[B2]], [[B2]]
; CHECK-NEXT:    [[TMP1:%.*]] = call i32 @use32(i32 [[C2]])
; CHECK-NEXT:    ret void
;
  %A1 = zext i32 %X to i64
  %B1 = add i64 %A1, 15
  %C1 = mul i64 %B1, %B1
  %T1 = trunc i64 %C1 to i48 ; leaf trunc
  %B2 = add i48 %T1, 15
  %C2 = mul i48 %B2, %B2
  %T2 = trunc i48 %C2 to i32
  call i32 @use32(i32 %T2)
  ret void
}

; Notice that there are two expression patterns below:
; 1. %T2->%C2->(%B2->(%T1, 15), %B2->(%T1, 15))
; 2. %T1`->%C1->(%B1->(%A1, 15), %B1->(%A1, 15))
;    (where %T1` is the reduced node of %T1 into trunc instruction)
define void @zext_as_a_leaf(i16 %X) {
; CHECK-LABEL: @zext_as_a_leaf(
; CHECK-NEXT:    [[A1:%.*]] = zext i16 [[X:%.*]] to i32
; CHECK-NEXT:    [[B1:%.*]] = add i32 [[A1]], 15
; CHECK-NEXT:    [[C1:%.*]] = mul i32 [[B1]], [[B1]]
; CHECK-NEXT:    [[B2:%.*]] = add i32 [[C1]], 15
; CHECK-NEXT:    [[C2:%.*]] = mul i32 [[B2]], [[B2]]
; CHECK-NEXT:    [[TMP1:%.*]] = call i32 @use32(i32 [[C2]])
; CHECK-NEXT:    ret void
;
  %A1 = zext i16 %X to i48
  %B1 = add i48 %A1, 15
  %C1 = mul i48 %B1, %B1
  %T1 = zext i48 %C1 to i64 ; leaf zext, which will turn into trunc
  %B2 = add i64 %T1, 15
  %C2 = mul i64 %B2, %B2
  %T2 = trunc i64 %C2 to i32
  call i32 @use32(i32 %T2)
  ret void
}