--- /dev/null
+; If the result of an instruction is only used outside of the loop, sink
+; the instruction to the exit blocks instead of executing it on every
+; iteration of the loop.
+;
+; RUN: llvm-as < %s | opt -licm | llvm-dis | grep -C1 mul | grep Out:
+
+int %test(int %N) {
+Entry:
+ br label %Loop
+Loop:
+ %N_addr.0.pn = phi int [ %dec, %Loop ], [ %N, %Entry ]
+ %tmp.6 = mul int %N, %N_addr.0.pn
+ %dec = add int %N_addr.0.pn, -1
+ %tmp.1 = setne int %N_addr.0.pn, 1
+ br bool %tmp.1, label %Loop, label %Out
+Out:
+ ret int %tmp.6
+}
--- /dev/null
+; To reduce register pressure, if a load is hoistable out of the loop, and the
+; result of the load is only used outside of the loop, sink the load instead of
+; hoisting it!
+;
+; RUN: llvm-as < %s | opt -licm | llvm-dis | grep -C1 load | grep Out:
+
+%X = global int 5
+
+int %test(int %N) {
+Entry:
+ br label %Loop
+Loop:
+ %N_addr.0.pn = phi int [ %dec, %Loop ], [ %N, %Entry ]
+ %tmp.6 = load int* %X
+ %dec = add int %N_addr.0.pn, -1
+ %tmp.1 = setne int %N_addr.0.pn, 1
+ br bool %tmp.1, label %Loop, label %Out
+Out:
+ ret int %tmp.6
+}
--- /dev/null
+; Potentially trapping instructions may be sunk as long as they are guaranteed
+; to be executed.
+;
+; RUN: llvm-as < %s | opt -licm | llvm-dis | grep -C1 div | grep Out:
+
+int %test(int %N) {
+Entry:
+ br label %Loop
+Loop:
+ %N_addr.0.pn = phi int [ %dec, %Loop ], [ %N, %Entry ]
+ %tmp.6 = div int %N, %N_addr.0.pn
+ %dec = add int %N_addr.0.pn, -1
+ %tmp.1 = setne int %N_addr.0.pn, 0
+ br bool %tmp.1, label %Loop, label %Out
+Out:
+ ret int %tmp.6
+}