1 ; NOTE: Assertions have been autogenerated by update_test_checks.py
2 ; RUN: opt -instsimplify -S < %s 2>&1 -pass-remarks-analysis=.* | FileCheck %s
4 ; Verify that warnings are emitted for the 2nd and 3rd tests.
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.
10 define void @test1() {
11 ; CHECK-LABEL: @test1(
14 call void @llvm.assume(i1 1)
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.
24 define i64 @PR31809() !dbg !7 {
25 ; CHECK-LABEL: @PR31809(
26 ; CHECK-NEXT: ret i64 3
29 %t1 = ptrtoint i32* %a to i64, !dbg !9
30 %cond = icmp eq i64 %t1, 3
31 call void @llvm.assume(i1 %cond)
35 ; Similar to above: there's no way to know which assumption is truthful,
36 ; so just don't crash.
38 define i8 @conflicting_assumptions(i8 %x) !dbg !10 {
39 ; CHECK-LABEL: @conflicting_assumptions(
40 ; CHECK-NEXT: [[ADD:%.*]] = add i8 [[X:%.*]], 1, !dbg !10
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 [[ADD]]
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)
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.
57 define void @PR36270(i32 %b) !dbg !13 {
58 ; CHECK-LABEL: @PR36270(
59 ; CHECK-NEXT: tail call void @llvm.assume(i1 false)
60 ; CHECK-NEXT: unreachable
62 %B7 = xor i32 -1, 2147483647
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)
72 declare void @llvm.assume(i1) nounwind
75 !llvm.module.flags = !{!3, !4, !5}
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")
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)