xref: /llvm-project/llvm/test/Transforms/InstCombine/assume-redundant.ll (revision 462cb3cd6cecd0511ecaf0e3ebcaba455ece587d)
1; RUN: opt -passes='require<domtree>,instcombine<no-verify-fixpoint>,require<domtree>' -S < %s | FileCheck %s
2; Note: The -loops above can be anything that requires the domtree, and is
3; necessary to work around a pass-manager bug.
4
5; In _Z3fooR1s we can only infer nuw on the gep after the IV has been
6; simplified, which we can't do in one iteration. (Note that nowadays
7; LoopUnroll would pre-simplify the IV and avoid the issue.)
8
9target datalayout = "e-m:e-i64:64-f80:128-n8:16:32:64-S128"
10target triple = "x86_64-unknown-linux-gnu"
11
12%struct.s = type { ptr }
13
14; Function Attrs: nounwind uwtable
15define void @_Z3fooR1s(ptr nocapture readonly dereferenceable(8) %x) #0 {
16
17; CHECK-LABEL: @_Z3fooR1s
18; CHECK: call void @llvm.assume
19; CHECK-NOT: call void @llvm.assume
20
21entry:
22  %0 = load ptr, ptr %x, align 8
23  %ptrint = ptrtoint ptr %0 to i64
24  %maskedptr = and i64 %ptrint, 31
25  %maskcond = icmp eq i64 %maskedptr, 0
26  br label %for.body
27
28for.body:                                         ; preds = %for.body, %entry
29  %indvars.iv = phi i64 [ 0, %entry ], [ %indvars.iv.next.1, %for.body ]
30  tail call void @llvm.assume(i1 %maskcond)
31  %arrayidx = getelementptr inbounds double, ptr %0, i64 %indvars.iv
32  %1 = load double, ptr %arrayidx, align 16
33  %add = fadd double %1, 1.000000e+00
34  tail call void @llvm.assume(i1 %maskcond)
35  %mul = fmul double %add, 2.000000e+00
36  store double %mul, ptr %arrayidx, align 16
37  %indvars.iv.next = add nuw nsw i64 %indvars.iv, 1
38  tail call void @llvm.assume(i1 %maskcond)
39  %arrayidx.1 = getelementptr inbounds double, ptr %0, i64 %indvars.iv.next
40  %2 = load double, ptr %arrayidx.1, align 8
41  %add.1 = fadd double %2, 1.000000e+00
42  tail call void @llvm.assume(i1 %maskcond)
43  %mul.1 = fmul double %add.1, 2.000000e+00
44  store double %mul.1, ptr %arrayidx.1, align 8
45  %indvars.iv.next.1 = add nuw nsw i64 %indvars.iv.next, 1
46  %exitcond.1 = icmp eq i64 %indvars.iv.next, 1599
47  br i1 %exitcond.1, label %for.end, label %for.body
48
49for.end:                                          ; preds = %for.body
50  ret void
51}
52
53declare align 8 ptr @get()
54
55; Check that redundant align assume is removed
56; CHECK-LABEL: @test
57; CHECK-NOT: call void @llvm.assume
58define void @test1() {
59  %p = call align 8 ptr @get()
60  %ptrint = ptrtoint ptr %p to i64
61  %maskedptr = and i64 %ptrint, 7
62  %maskcond = icmp eq i64 %maskedptr, 0
63  call void @llvm.assume(i1 %maskcond)
64  ret void
65}
66
67; Check that redundant align assume is removed
68; CHECK-LABEL: @test
69; CHECK-NOT: call void @llvm.assume
70define void @test3() {
71  %p = alloca i8, align 8
72  %ptrint = ptrtoint ptr %p to i64
73  %maskedptr = and i64 %ptrint, 7
74  %maskcond = icmp eq i64 %maskedptr, 0
75  call void @llvm.assume(i1 %maskcond)
76  ret void
77}
78
79; Function Attrs: nounwind
80declare void @llvm.assume(i1) #1
81
82attributes #0 = { nounwind uwtable }
83attributes #1 = { nounwind }
84
85