1; NOTE: Assertions have been autogenerated by update_test_checks.py
2; RUN: opt -instsimplify -S < %s 2>&1 -pass-remarks-analysis=.* | FileCheck %s
3
4; Verify that warnings are emitted for the 2nd and 3rd tests.
5
6; CHECK: remark: /tmp/s.c:1:13: Detected conflicting code assumptions.
7; CHECK: remark: /tmp/s.c:4:10: Detected conflicting code assumptions.
8; CHECK: remark: /tmp/s.c:5:50: Detected conflicting code assumptions.
9
10define void @test1() {
11; CHECK-LABEL: @test1(
12; CHECK:         ret void
13;
14  call void @llvm.assume(i1 1)
15  ret void
16
17}
18
19; The alloca guarantees that the low bits of %a are zero because of alignment.
20; The assume says the opposite. The assume is processed last, so that's the
21; return value. There's no way to win (we can't undo transforms that happened
22; based on half-truths), so just don't crash.
23
24define i64 @PR31809() !dbg !7 {
25; CHECK-LABEL: @PR31809(
26; CHECK-NEXT:    ret i64 3
27;
28  %a = alloca i32
29  %t1 = ptrtoint i32* %a to i64, !dbg !9
30  %cond = icmp eq i64 %t1, 3
31  call void @llvm.assume(i1 %cond)
32  ret i64 %t1
33}
34
35; Similar to above: there's no way to know which assumption is truthful,
36; so just don't crash. The second icmp+assume gets processed later, so that
37; determines the return value.
38
39define i8 @conflicting_assumptions(i8 %x) !dbg !10 {
40; CHECK-LABEL: @conflicting_assumptions(
41; CHECK-NEXT:    call void @llvm.assume(i1 false)
42; CHECK-NEXT:    [[COND2:%.*]] = icmp eq i8 %x, 4
43; CHECK-NEXT:    call void @llvm.assume(i1 [[COND2]])
44; CHECK-NEXT:    ret i8 5
45;
46  %add = add i8 %x, 1, !dbg !11
47  %cond1 = icmp eq i8 %x, 3
48  call void @llvm.assume(i1 %cond1)
49  %cond2 = icmp eq i8 %x, 4
50  call void @llvm.assume(i1 %cond2)
51  ret i8 %add
52}
53
54; Another case of conflicting assumptions. This would crash because we'd
55; try to set more known bits than existed in the known bits struct.
56
57define void @PR36270(i32 %b) !dbg !13 {
58; CHECK-LABEL: @PR36270(
59; CHECK-NEXT:    tail call void @llvm.assume(i1 false)
60; CHECK-NEXT:    unreachable
61;
62  %B7 = xor i32 -1, 2147483647
63  %and1 = and i32 %b, 3
64  %B12 = lshr i32 %B7, %and1, !dbg !14
65  %C1 = icmp ult i32 %and1, %B12
66  tail call void @llvm.assume(i1 %C1)
67  %cmp2 = icmp eq i32 0, %B12
68  tail call void @llvm.assume(i1 %cmp2)
69  unreachable
70}
71
72declare void @llvm.assume(i1) nounwind
73
74!llvm.dbg.cu = !{!0}
75!llvm.module.flags = !{!3, !4, !5}
76!llvm.ident = !{!6}
77
78!0 = distinct !DICompileUnit(language: DW_LANG_C99, file: !1, producer: "clang version 4.0.0 (trunk 282540) (llvm/trunk 282542)", isOptimized: true, runtimeVersion: 0, emissionKind: LineTablesOnly, enums: !2)
79!1 = !DIFile(filename: "/tmp/s.c", directory: "/tmp")
80!2 = !{}
81!3 = !{i32 2, !"Dwarf Version", i32 4}
82!4 = !{i32 2, !"Debug Info Version", i32 3}
83!5 = !{i32 1, !"PIC Level", i32 2}
84!6 = !{!"clang version 4.0.0 (trunk 282540) (llvm/trunk 282542)"}
85!7 = distinct !DISubprogram(name: "foo", scope: !1, file: !1, line: 1, type: !8, isLocal: false, isDefinition: true, scopeLine: 1, isOptimized: true, unit: !0, retainedNodes: !2)
86!8 = !DISubroutineType(types: !2)
87!9 = !DILocation(line: 1, column: 13, scope: !7)
88!10 = distinct !DISubprogram(name: "bar", scope: !1, file: !1, line: 3, type: !8, isLocal: false, isDefinition: true, scopeLine: 3, isOptimized: true, unit: !0, retainedNodes: !2)
89!11 = !DILocation(line: 4, column: 10, scope: !10)
90!12 = !DILocation(line: 4, column: 3, scope: !10)
91!13 = distinct !DISubprogram(name: "PR36270", scope: !1, file: !1, line: 3, type: !8, isLocal: false, isDefinition: true, scopeLine: 3, isOptimized: true, unit: !0, retainedNodes: !2)
92!14 = !DILocation(line: 5, column: 50, scope: !13)
93
94