blob: 66f2120f2928bc5500a9290c4452c24e25a44d54 [file] [log] [blame]
Sanjay Patel69632442016-03-25 20:12:25 +00001; NOTE: Assertions have been autogenerated by update_test_checks.py
Sanjay Patel54656ca2017-02-06 18:26:06 +00002; 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.
Hal Finkel93046912014-07-25 21:13:35 +00008
9define void @test1() {
Sanjay Patel69632442016-03-25 20:12:25 +000010; CHECK-LABEL: @test1(
11; CHECK: ret void
12;
Hal Finkel93046912014-07-25 21:13:35 +000013 call void @llvm.assume(i1 1)
14 ret void
15
Hal Finkel93046912014-07-25 21:13:35 +000016}
17
Sanjay Patel25f6d712017-02-01 15:41:32 +000018; The alloca guarantees that the low bits of %a are zero because of alignment.
19; The assume says the opposite. The assume is processed last, so that's the
20; return value. There's no way to win (we can't undo transforms that happened
21; based on half-truths), so just don't crash.
22
Sanjay Patel54656ca2017-02-06 18:26:06 +000023define i64 @PR31809() !dbg !7 {
Sanjay Patel25f6d712017-02-01 15:41:32 +000024; CHECK-LABEL: @PR31809(
25; CHECK-NEXT: ret i64 3
26;
27 %a = alloca i32
Sanjay Patel54656ca2017-02-06 18:26:06 +000028 %t1 = ptrtoint i32* %a to i64, !dbg !9
Sanjay Patel25f6d712017-02-01 15:41:32 +000029 %cond = icmp eq i64 %t1, 3
30 call void @llvm.assume(i1 %cond)
31 ret i64 %t1
32}
33
34; Similar to above: there's no way to know which assumption is truthful,
35; so just don't crash. The second icmp+assume gets processed later, so that
Sanjay Patel52e4e652017-02-01 22:27:34 +000036; determines the return value.
Sanjay Patel25f6d712017-02-01 15:41:32 +000037
Sanjay Patel54656ca2017-02-06 18:26:06 +000038define i8 @conflicting_assumptions(i8 %x) !dbg !10 {
Sanjay Patel25f6d712017-02-01 15:41:32 +000039; CHECK-LABEL: @conflicting_assumptions(
40; CHECK-NEXT: call void @llvm.assume(i1 false)
41; CHECK-NEXT: [[COND2:%.*]] = icmp eq i8 %x, 4
42; CHECK-NEXT: call void @llvm.assume(i1 [[COND2]])
43; CHECK-NEXT: ret i8 5
44;
Sanjay Patel54656ca2017-02-06 18:26:06 +000045 %add = add i8 %x, 1, !dbg !11
Sanjay Patel25f6d712017-02-01 15:41:32 +000046 %cond1 = icmp eq i8 %x, 3
47 call void @llvm.assume(i1 %cond1)
48 %cond2 = icmp eq i8 %x, 4
49 call void @llvm.assume(i1 %cond2)
50 ret i8 %add
51}
52
Hal Finkel93046912014-07-25 21:13:35 +000053declare void @llvm.assume(i1) nounwind
54
Sanjay Patel54656ca2017-02-06 18:26:06 +000055!llvm.dbg.cu = !{!0}
56!llvm.module.flags = !{!3, !4, !5}
57!llvm.ident = !{!6}
58
59!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)
60!1 = !DIFile(filename: "/tmp/s.c", directory: "/tmp")
61!2 = !{}
62!3 = !{i32 2, !"Dwarf Version", i32 4}
63!4 = !{i32 2, !"Debug Info Version", i32 3}
64!5 = !{i32 1, !"PIC Level", i32 2}
65!6 = !{!"clang version 4.0.0 (trunk 282540) (llvm/trunk 282542)"}
66!7 = distinct !DISubprogram(name: "foo", scope: !1, file: !1, line: 1, type: !8, isLocal: false, isDefinition: true, scopeLine: 1, isOptimized: true, unit: !0, variables: !2)
67!8 = !DISubroutineType(types: !2)
68!9 = !DILocation(line: 1, column: 13, scope: !7)
69!10 = distinct !DISubprogram(name: "bar", scope: !1, file: !1, line: 3, type: !8, isLocal: false, isDefinition: true, scopeLine: 3, isOptimized: true, unit: !0, variables: !2)
70!11 = !DILocation(line: 4, column: 10, scope: !10)
71!12 = !DILocation(line: 4, column: 3, scope: !10)
72