xref: /llvm-project/llvm/test/Transforms/Reassociate/optional-flags.ll (revision 211cf8a384ebb29787367c8fd5858e2a5ed3c10f)
1; NOTE: Assertions have been autogenerated by utils/update_test_checks.py
2; RUN: opt -S -passes=reassociate < %s | FileCheck %s
3; rdar://8944681
4
5; Reassociate should clear optional flags like nsw when reassociating.
6
7define i64 @test0(i64 %a, i64 %b, i64 %c) {
8;
9; CHECK-LABEL: @test0(
10; CHECK-NEXT:    [[Y:%.*]] = add i64 [[B:%.*]], [[A:%.*]]
11; CHECK-NEXT:    [[Z:%.*]] = add i64 [[Y]], [[C:%.*]]
12; CHECK-NEXT:    ret i64 [[Z]]
13;
14  %y = add nsw i64 %c, %b
15  %z = add i64 %y, %a
16  ret i64 %z
17}
18
19define i64 @test1(i64 %a, i64 %b, i64 %c) {
20;
21; CHECK-LABEL: @test1(
22; CHECK-NEXT:    [[Y:%.*]] = add i64 [[B:%.*]], [[A:%.*]]
23; CHECK-NEXT:    [[Z:%.*]] = add i64 [[Y]], [[C:%.*]]
24; CHECK-NEXT:    ret i64 [[Z]]
25;
26  %y = add i64 %c, %b
27  %z = add nsw i64 %y, %a
28  ret i64 %z
29}
30
31; PR9215
32define i32 @test2(i32 %x, i32 %y) {
33;
34; CHECK-LABEL: @test2(
35; CHECK-NEXT:    [[S:%.*]] = add nsw i32 [[Y:%.*]], [[X:%.*]]
36; CHECK-NEXT:    ret i32 [[S]]
37;
38  %s = add nsw i32 %x, %y
39  ret i32 %s
40}
41