Sanjay Patel | 6963244 | 2016-03-25 20:12:25 +0000 | [diff] [blame] | 1 | ; NOTE: Assertions have been autogenerated by update_test_checks.py |
Sanjay Patel | 54656ca | 2017-02-06 18:26:06 +0000 | [diff] [blame] | 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. |
Hal Finkel | 9304691 | 2014-07-25 21:13:35 +0000 | [diff] [blame] | 8 | |
| 9 | define void @test1() { |
Sanjay Patel | 6963244 | 2016-03-25 20:12:25 +0000 | [diff] [blame] | 10 | ; CHECK-LABEL: @test1( |
| 11 | ; CHECK: ret void |
| 12 | ; |
Hal Finkel | 9304691 | 2014-07-25 21:13:35 +0000 | [diff] [blame] | 13 | call void @llvm.assume(i1 1) |
| 14 | ret void |
| 15 | |
Hal Finkel | 9304691 | 2014-07-25 21:13:35 +0000 | [diff] [blame] | 16 | } |
| 17 | |
Sanjay Patel | 25f6d71 | 2017-02-01 15:41:32 +0000 | [diff] [blame] | 18 | ; 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 Patel | 54656ca | 2017-02-06 18:26:06 +0000 | [diff] [blame] | 23 | define i64 @PR31809() !dbg !7 { |
Sanjay Patel | 25f6d71 | 2017-02-01 15:41:32 +0000 | [diff] [blame] | 24 | ; CHECK-LABEL: @PR31809( |
| 25 | ; CHECK-NEXT: ret i64 3 |
| 26 | ; |
| 27 | %a = alloca i32 |
Sanjay Patel | 54656ca | 2017-02-06 18:26:06 +0000 | [diff] [blame] | 28 | %t1 = ptrtoint i32* %a to i64, !dbg !9 |
Sanjay Patel | 25f6d71 | 2017-02-01 15:41:32 +0000 | [diff] [blame] | 29 | %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 Patel | 52e4e65 | 2017-02-01 22:27:34 +0000 | [diff] [blame] | 36 | ; determines the return value. |
Sanjay Patel | 25f6d71 | 2017-02-01 15:41:32 +0000 | [diff] [blame] | 37 | |
Sanjay Patel | 54656ca | 2017-02-06 18:26:06 +0000 | [diff] [blame] | 38 | define i8 @conflicting_assumptions(i8 %x) !dbg !10 { |
Sanjay Patel | 25f6d71 | 2017-02-01 15:41:32 +0000 | [diff] [blame] | 39 | ; 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 Patel | 54656ca | 2017-02-06 18:26:06 +0000 | [diff] [blame] | 45 | %add = add i8 %x, 1, !dbg !11 |
Sanjay Patel | 25f6d71 | 2017-02-01 15:41:32 +0000 | [diff] [blame] | 46 | %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 Finkel | 9304691 | 2014-07-25 21:13:35 +0000 | [diff] [blame] | 53 | declare void @llvm.assume(i1) nounwind |
| 54 | |
Sanjay Patel | 54656ca | 2017-02-06 18:26:06 +0000 | [diff] [blame] | 55 | !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 | |