xref: /llvm-project/llvm/test/Transforms/LoopVectorize/scalarized-bitcast.ll (revision c836b8956d393f98e0d4e136799a33f1bd06e5f5)
1; REQUIRES: asserts
2; RUN: opt -passes=loop-vectorize -force-vector-width=2 -debug-only=loop-vectorize --disable-output -S -o - < %s 2>&1 | FileCheck %s
3
4%struct.foo = type { i32, i64 }
5
6; CHECK: LV: Found an estimated cost of 0 for VF 2 For instruction:   %0 = bitcast ptr %b to ptr
7
8; The bitcast below will be scalarized due to the predication in the loop. Bitcasts
9; between pointer types should be treated as free, despite the scalarization.
10define void @foo(ptr noalias nocapture %in, ptr noalias nocapture readnone %out, i64 %n) {
11entry:
12  br label %for.body
13
14for.body:                                         ; preds = %entry, %if.end
15  %i.012 = phi i64 [ %inc, %if.end ], [ 0, %entry ]
16  %b = getelementptr inbounds %struct.foo, ptr %in, i64 %i.012, i32 1
17  %0 = bitcast ptr %b to ptr
18  %a = getelementptr inbounds %struct.foo, ptr %in, i64 %i.012, i32 0
19  %1 = load i32, ptr %a, align 8
20  %tobool.not = icmp eq i32 %1, 0
21  br i1 %tobool.not, label %if.end, label %land.lhs.true
22
23land.lhs.true:                                    ; preds = %for.body
24  %2 = load i32, ptr %0, align 4
25  %cmp2 = icmp sgt i32 %2, 0
26  br i1 %cmp2, label %if.then, label %if.end
27
28if.then:                                          ; preds = %land.lhs.true
29  %sub = add nsw i32 %2, -1
30  store i32 %sub, ptr %0, align 4
31  br label %if.end
32
33if.end:                                           ; preds = %if.then, %land.lhs.true, %for.body
34  %inc = add nuw nsw i64 %i.012, 1
35  %exitcond.not = icmp eq i64 %inc, %n
36  br i1 %exitcond.not, label %for.end, label %for.body
37
38for.end:                                          ; preds = %if.end
39  ret void
40}
41