1 ; NOTE: Assertions have been autogenerated by utils/update_test_checks.py
2 ; RUN: opt < %s -instcombine -S | FileCheck %s
4 ; This testcase corresponds to PR362, which notices that this horrible code
5 ; is generated by the C++ front-end and LLVM optimizers, which has lots of
6 ; loads and other stuff that are unneeded.
8 ; Instcombine should propagate the load through the select instructions to
9 ; allow elimination of the extra stuff by the mem2reg pass.
11 define void @_Z5test1RiS_(i32* %x, i32* %y) {
12 ; CHECK-LABEL: @_Z5test1RiS_(
14 ; CHECK-NEXT: [[TMP_1_I:%.*]] = load i32, i32* [[Y:%.*]], align 4
15 ; CHECK-NEXT: [[TMP_3_I:%.*]] = load i32, i32* [[X:%.*]], align 4
16 ; CHECK-NEXT: [[TMP_4_I:%.*]] = icmp slt i32 [[TMP_1_I]], [[TMP_3_I]]
17 ; CHECK-NEXT: [[TMP_4:%.*]] = select i1 [[TMP_4_I]], i32 [[TMP_1_I]], i32 [[TMP_3_I]]
18 ; CHECK-NEXT: store i32 [[TMP_4]], i32* [[X]], align 4
19 ; CHECK-NEXT: ret void
22 %tmp.1.i = load i32, i32* %y ; <i32> [#uses=1]
23 %tmp.3.i = load i32, i32* %x ; <i32> [#uses=1]
24 %tmp.4.i = icmp slt i32 %tmp.1.i, %tmp.3.i ; <i1> [#uses=1]
25 %retval.i = select i1 %tmp.4.i, i32* %y, i32* %x ; <i32*> [#uses=1]
26 %tmp.4 = load i32, i32* %retval.i ; <i32> [#uses=1]
27 store i32 %tmp.4, i32* %x
31 define void @_Z5test2RiS_(i32* %x, i32* %y) {
32 ; CHECK-LABEL: @_Z5test2RiS_(
34 ; CHECK-NEXT: [[TMP_2:%.*]] = load i32, i32* [[X:%.*]], align 4
35 ; CHECK-NEXT: [[TMP_3_I:%.*]] = load i32, i32* [[Y:%.*]], align 4
36 ; CHECK-NEXT: [[TMP_4_I:%.*]] = icmp slt i32 [[TMP_2]], [[TMP_3_I]]
37 ; CHECK-NEXT: [[TMP_6:%.*]] = select i1 [[TMP_4_I]], i32 [[TMP_3_I]], i32 [[TMP_2]]
38 ; CHECK-NEXT: store i32 [[TMP_6]], i32* [[Y]], align 4
39 ; CHECK-NEXT: ret void
42 %tmp.0 = alloca i32 ; <i32*> [#uses=2]
43 %tmp.2 = load i32, i32* %x ; <i32> [#uses=2]
44 store i32 %tmp.2, i32* %tmp.0
45 %tmp.3.i = load i32, i32* %y ; <i32> [#uses=1]
46 %tmp.4.i = icmp slt i32 %tmp.2, %tmp.3.i ; <i1> [#uses=1]
47 %retval.i = select i1 %tmp.4.i, i32* %y, i32* %tmp.0 ; <i32*> [#uses=1]
48 %tmp.6 = load i32, i32* %retval.i ; <i32> [#uses=1]
49 store i32 %tmp.6, i32* %y