summaryrefslogtreecommitdiffstats
path: root/llvm/test/Transforms/Reassociate/negation.ll
blob: e1f9a421a9c0050346e3c296ee79428831a4e5a6 (plain)
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
; NOTE: Assertions have been autogenerated by utils/update_test_checks.py
; RUN: opt < %s -reassociate -instcombine -S | FileCheck %s

; Test that we can turn things like X*-(Y*Z) -> X*-1*Y*Z.

define i32 @test1(i32 %a, i32 %b, i32 %z) {
; CHECK-LABEL: @test1(
; CHECK-NEXT:    [[E:%.*]] = mul i32 [[A:%.*]], 12345
; CHECK-NEXT:    [[F:%.*]] = mul i32 [[E]], [[B:%.*]]
; CHECK-NEXT:    [[G:%.*]] = mul i32 [[F]], [[Z:%.*]]
; CHECK-NEXT:    ret i32 [[G]]
;
  %c = sub i32 0, %z
  %d = mul i32 %a, %b
  %e = mul i32 %c, %d
  %f = mul i32 %e, 12345
  %g = sub i32 0, %f
  ret i32 %g
}

define i32 @test2(i32 %a, i32 %b, i32 %z) {
; CHECK-LABEL: @test2(
; CHECK-NEXT:    [[E:%.*]] = mul i32 [[A:%.*]], 40
; CHECK-NEXT:    [[F:%.*]] = mul i32 [[E]], [[Z:%.*]]
; CHECK-NEXT:    ret i32 [[F]]
;
  %d = mul i32 %z, 40
  %c = sub i32 0, %d
  %e = mul i32 %a, %c
  %f = sub i32 0, %e
  ret i32 %f
}

define <2 x i32> @negate_vec_undefs(<2 x i32> %a, <2 x i32> %b, <2 x i32> %z) {
; CHECK-LABEL: @negate_vec_undefs(
; CHECK-NEXT:    [[TMP1:%.*]] = mul <2 x i32> [[Z:%.*]], <i32 -40, i32 -40>
; CHECK-NEXT:    [[E:%.*]] = mul <2 x i32> [[TMP1]], [[A:%.*]]
; CHECK-NEXT:    [[F:%.*]] = sub <2 x i32> <i32 0, i32 undef>, [[E]]
; CHECK-NEXT:    ret <2 x i32> [[F]]
;
  %d = mul <2 x i32> %z, <i32 40, i32 40>
  %c = sub <2 x i32> <i32 0, i32 undef>, %d
  %e = mul <2 x i32> %a, %c
  %f = sub <2 x i32> <i32 0, i32 undef>, %e
  ret <2 x i32> %f
}

define i32 @not_not(i32 %a, i32 %b, i32 %z) {
; CHECK-LABEL: @not_not(
; CHECK-NEXT:    [[D:%.*]] = and i32 [[Z:%.*]], 40
; CHECK-NEXT:    [[A_NOT:%.*]] = xor i32 [[A:%.*]], -1
; CHECK-NEXT:    [[F:%.*]] = and i32 [[D]], [[A_NOT]]
; CHECK-NEXT:    ret i32 [[F]]
;
  %d = and i32 %z, 40
  %c = xor i32 -1, %d
  %e = or i32 %a, %c
  %f = xor i32 -1, %e
  ret i32 %f
}

define <2 x i32> @not_vec_undefs(<2 x i32> %a, <2 x i32> %b, <2 x i32> %z) {
; CHECK-LABEL: @not_vec_undefs(
; CHECK-NEXT:    [[D:%.*]] = or <2 x i32> [[Z:%.*]], <i32 40, i32 40>
; CHECK-NEXT:    [[A_NOT:%.*]] = xor <2 x i32> [[A:%.*]], <i32 -1, i32 -1>
; CHECK-NEXT:    [[F:%.*]] = or <2 x i32> [[D]], [[A_NOT]]
; CHECK-NEXT:    ret <2 x i32> [[F]]
;
  %d = or <2 x i32> %z, <i32 40, i32 40>
  %c = xor <2 x i32> <i32 undef, i32 -1>, %d
  %e = and <2 x i32> %a, %c
  %f = xor <2 x i32> <i32 undef, i32 -1>, %e
  ret <2 x i32> %f
}

OpenPOWER on IntegriCloud