1 ; NOTE: Assertions have been autogenerated by utils/update_test_checks.py
2 ; RUN: opt < %s -nary-reassociate -S | FileCheck %s
3 ; RUN: opt < %s -passes='nary-reassociate' -S | FileCheck %s
5 define i32 @foo(i32 %t4) {
8 ; CHECK-NEXT: [[T13:%.*]] = add i32 [[T4:%.*]], -128
9 ; CHECK-NEXT: [[T14:%.*]] = add i32 [[T13]], 8
10 ; CHECK-NEXT: [[T23:%.*]] = add i32 [[T13]], 119
11 ; CHECK-NEXT: ret i32 [[T23]]
15 %t13 = add i32 %t4, -128 ; deleted
16 %t14 = add i32 %t13, 8 ; => %t5 + -128
17 %t21 = add i32 119, %t4
18 ; do not rewrite %t23 against %t13 because %t13 is already deleted
19 %t23 = add i32 %t21, -128
23 ; This is essentially the same test as the previous one but intermidiate result (t14) has a use.
24 define i32 @foo2(i32 %t4) {
27 ; CHECK-NEXT: [[T13:%.*]] = add i32 [[T4:%.*]], -128
28 ; CHECK-NEXT: [[T14:%.*]] = add i32 [[T13]], 8
29 ; CHECK-NEXT: [[T23:%.*]] = add i32 [[T13]], 119
30 ; CHECK-NEXT: [[RES:%.*]] = add i32 [[T14]], [[T23]]
31 ; CHECK-NEXT: ret i32 [[RES]]
34 %t5 = add i32 %t4, 8 ; initially dead
35 %t13 = add i32 %t4, -128
36 %t14 = add i32 %t13, 8
37 %t21 = add i32 119, %t4 ; => dead after reassociation
38 %t23 = add i32 %t21, -128; => reassociated to t13 + 119
39 %res = add i32 %t14, %t23