1 ; RUN: opt < %s -passes=licm -S | FileCheck %s
2 ; RUN: opt -passes='require<aa>,require<target-ir>,require<scalar-evolution>,require<opt-remark-emit>,loop-mssa(licm)' < %s -S | FileCheck %s
4 target datalayout = "e-m:e-i64:64-f80:128-n8:16:32:64-S128"
5 target triple = "x86_64-unknown-linux-gnu"
7 define i32 @f(i32 %x) {
11 for.body: ; preds = %entry, %for.body
12 %storemerge4 = phi i32 [ 0, %entry ], [ %inc, %for.body ]
13 %mul = mul nsw i32 %x, %x
14 %add2 = add nsw i32 %mul, %x
15 %mul3 = add nsw i32 %add2, %mul
16 %inc = add nsw i32 %storemerge4, 1
17 %cmp = icmp slt i32 %inc, 100
18 br i1 %cmp, label %for.body, label %for.end
20 for.end: ; preds = %for.body
21 %a9.0.lcssa = phi i32 [ %mul3, %for.body ]
25 ; Test that there is exactly one copy of mul nsw i32 %x, %x in the exit block.
26 ; CHECK: define i32 @f(i32 [[X:%.*]])
28 ; CHECK-NOT: mul nsw i32 [[X]], [[X]]
29 ; CHECK: mul nsw i32 [[X]], [[X]]
30 ; CHECK-NOT: mul nsw i32 [[X]], [[X]]