Skip to content

Commit a73e251

Browse files
authored
Merge pull request #10108 from fhahn/ce-passes-next
[Passes] Run ConstraintElimination after loop optimizations. Update pipeline to match next. rdar://128576231
2 parents 32babdb + 513230b commit a73e251

11 files changed

+41
-202
lines changed

clang/test/BoundsSafety/CodeGen/opt-remarks/bounds-safety-missed-binop-overflow.c

Lines changed: 14 additions & 37 deletions
Original file line numberDiff line numberDiff line change
@@ -58,7 +58,7 @@ void test_sub(int* __indexable A, int N) {
5858
// OPT-REM-NEXT: Function: test_shl
5959
// OPT-REM-NEXT: Args:
6060
// OPT-REM-NEXT: - String: 'Annotated '
61-
// OPT-REM-NEXT: - count: '2'
61+
// OPT-REM-NEXT: - count: '3'
6262
// OPT-REM-NEXT: - String: ' instructions with '
6363
// OPT-REM-NEXT: - type: bounds-safety-missed-optimization-nuw
6464
// OPT-REM-NEXT: ...
@@ -229,23 +229,26 @@ void test_sub(int* __indexable A, int N) {
229229
// OPT-REM-NEXT: Function: test_shl
230230
// OPT-REM-NEXT: Args:
231231
// OPT-REM-NEXT: - String: 'Inserted '
232-
// OPT-REM-NEXT: - count: '4'
232+
// OPT-REM-NEXT: - count: '5'
233233
// OPT-REM-NEXT: - String: ' LLVM IR instruction'
234234
// OPT-REM-NEXT: - String: s
235235
// OPT-REM-NEXT: - String: "\n"
236236
// OPT-REM-NEXT: - String: "used for:\n"
237-
// OPT-REM-NEXT: - String: bounds-safety-check-ptr-lt-upper-bound, bounds-safety-check-ptr-ge-lower-bound
237+
// OPT-REM-NEXT: - String: bounds-safety-missed-optimization-nuw, bounds-safety-check-ptr-lt-upper-bound, bounds-safety-check-ptr-ge-lower-bound
238238
// OPT-REM-NEXT: - String: |
239239
// OPT-REM-NEXT: {{^[ ]+$}}
240240
// OPT-REM-NEXT: {{^[ ]+$}}
241241
// OPT-REM-NEXT: instructions:
242242
// OPT-REM-EMPTY:
243243
// OPT-REM-NEXT: - String: |
244+
// OPT-REM-NEXT: other (LLVM IR 'shl')
244245
// OPT-REM-NEXT: cmp ult (LLVM IR 'icmp')
245246
// OPT-REM-NEXT: cmp uge (LLVM IR 'icmp')
246247
// OPT-REM-NEXT: and (LLVM IR 'and')
247248
// OPT-REM-NEXT: cond branch (LLVM IR 'br')
248249
// OPT-REM-EMPTY:
250+
// OPT-REM-NEXT: - String: "Missed Optimization Info\n"
251+
// OPT-REM-NEXT: - String: Check can not be removed because the arithmetic operation might wrap in the unsigned sense. Optimize the check by adding conditions to check for overflow before doing the operation
249252
// OPT-REM-NEXT: ...
250253

251254
// OPT-REM-NEXT: --- !Analysis
@@ -269,7 +272,7 @@ void test_sub(int* __indexable A, int N) {
269272
// OPT-REM-NEXT: Function: test_mul
270273
// OPT-REM-NEXT: Args:
271274
// OPT-REM-NEXT: - String: 'Annotated '
272-
// OPT-REM-NEXT: - count: '2'
275+
// OPT-REM-NEXT: - count: '3'
273276
// OPT-REM-NEXT: - String: ' instructions with '
274277
// OPT-REM-NEXT: - type: bounds-safety-missed-optimization-nuw
275278
// OPT-REM-NEXT: ...
@@ -440,24 +443,25 @@ void test_sub(int* __indexable A, int N) {
440443
// OPT-REM-NEXT: Function: test_mul
441444
// OPT-REM-NEXT: Args:
442445
// OPT-REM-NEXT: - String: 'Inserted '
443-
// OPT-REM-NEXT: - count: '4'
446+
// OPT-REM-NEXT: - count: '5'
444447
// OPT-REM-NEXT: - String: ' LLVM IR instruction'
445448
// OPT-REM-NEXT: - String: s
446449
// OPT-REM-NEXT: - String: "\n"
447450
// OPT-REM-NEXT: - String: "used for:\n"
448-
// OPT-REM-NEXT: - String: bounds-safety-check-ptr-lt-upper-bound, bounds-safety-check-ptr-ge-lower-bound
451+
// OPT-REM-NEXT: - String: bounds-safety-missed-optimization-nuw, bounds-safety-check-ptr-lt-upper-bound, bounds-safety-check-ptr-ge-lower-bound
449452
// OPT-REM-NEXT: - String: |
450453
// OPT-REM-NEXT: {{^[ ]+$}}
451454
// OPT-REM-NEXT: {{^[ ]+$}}
452455
// OPT-REM-NEXT: instructions:
453456
// OPT-REM-EMPTY:
454457
// OPT-REM-NEXT: - String: |
458+
// OPT-REM-NEXT: other (LLVM IR 'shl')
455459
// OPT-REM-NEXT: cmp ult (LLVM IR 'icmp')
456460
// OPT-REM-NEXT: cmp uge (LLVM IR 'icmp')
457461
// OPT-REM-NEXT: and (LLVM IR 'and')
458462
// OPT-REM-NEXT: cond branch (LLVM IR 'br')
459463
// OPT-REM-EMPTY:
460-
// OPT-REM-NEXT: ...
464+
// OPT-REM: ...
461465

462466
// OPT-REM-NEXT: --- !Analysis
463467
// OPT-REM-NEXT: Pass: annotation-remarks
@@ -493,7 +497,7 @@ void test_sub(int* __indexable A, int N) {
493497
// OPT-REM-NEXT: Function: test_add
494498
// OPT-REM-NEXT: Args:
495499
// OPT-REM-NEXT: - String: 'Annotated '
496-
// OPT-REM-NEXT: - count: '4'
500+
// OPT-REM-NEXT: - count: '2'
497501
// OPT-REM-NEXT: - String: ' instructions with '
498502
// OPT-REM-NEXT: - type: bounds-safety-check-ptr-lt-upper-bound
499503
// OPT-REM-NEXT: ...
@@ -506,7 +510,7 @@ void test_sub(int* __indexable A, int N) {
506510
// OPT-REM-NEXT: Function: test_add
507511
// OPT-REM-NEXT: Args:
508512
// OPT-REM-NEXT: - String: 'Annotated '
509-
// OPT-REM-NEXT: - count: '4'
513+
// OPT-REM-NEXT: - count: '2'
510514
// OPT-REM-NEXT: - String: ' instructions with '
511515
// OPT-REM-NEXT: - type: bounds-safety-check-ptr-ge-lower-bound
512516
// OPT-REM-NEXT: ...
@@ -519,7 +523,7 @@ void test_sub(int* __indexable A, int N) {
519523
// OPT-REM-NEXT: Function: test_add
520524
// OPT-REM-NEXT: Args:
521525
// OPT-REM-NEXT: - String: 'Annotated '
522-
// OPT-REM-NEXT: - count: '13'
526+
// OPT-REM-NEXT: - count: '9'
523527
// OPT-REM-NEXT: - String: ' instructions with '
524528
// OPT-REM-NEXT: - type: bounds-safety-total-summary
525529
// OPT-REM-NEXT: ...
@@ -643,33 +647,6 @@ void test_sub(int* __indexable A, int N) {
643647
// OPT-REM-NEXT: - String: "trap (LLVM IR 'call')\nother (LLVM IR 'unreachable')"
644648
// OPT-REM-NEXT: ...
645649

646-
// OPT-REM-NEXT: --- !Analysis
647-
// OPT-REM-NEXT: Pass: annotation-remarks
648-
// OPT-REM-NEXT: Name: BoundsSafetyCheck
649-
// OPT-REM-NEXT: DebugLoc: { File: '{{.*}}bounds-safety-missed-binop-overflow.c',
650-
// OPT-REM-NEXT: Line: 29, Column: 11 }
651-
// OPT-REM-NEXT: Function: test_add
652-
// OPT-REM-NEXT: Args:
653-
// OPT-REM-NEXT: - String: 'Inserted '
654-
// OPT-REM-NEXT: - count: '4'
655-
// OPT-REM-NEXT: - String: ' LLVM IR instruction'
656-
// OPT-REM-NEXT: - String: s
657-
// OPT-REM-NEXT: - String: "\n"
658-
// OPT-REM-NEXT: - String: "used for:\n"
659-
// OPT-REM-NEXT: - String: bounds-safety-check-ptr-lt-upper-bound, bounds-safety-check-ptr-ge-lower-bound
660-
// OPT-REM-NEXT: - String: |
661-
// OPT-REM-NEXT: {{^[ ]+$}}
662-
// OPT-REM-NEXT: {{^[ ]+$}}
663-
// OPT-REM-NEXT: instructions:
664-
// OPT-REM-EMPTY:
665-
// OPT-REM-NEXT: - String: |
666-
// OPT-REM-NEXT: cmp ult (LLVM IR 'icmp')
667-
// OPT-REM-NEXT: cmp uge (LLVM IR 'icmp')
668-
// OPT-REM-NEXT: and (LLVM IR 'and')
669-
// OPT-REM-NEXT: cond branch (LLVM IR 'br')
670-
// OPT-REM-EMPTY:
671-
// OPT-REM-NEXT: ...
672-
673650
// OPT-REM-NEXT: --- !Analysis
674651
// OPT-REM-NEXT: Pass: annotation-remarks
675652
// OPT-REM-NEXT: Name: AnnotationSummary

clang/test/BoundsSafety/CodeGen/range-check-optimizations-structs-with-arrays-no-bringup-missing-checks.c

Lines changed: 5 additions & 35 deletions
Original file line numberDiff line numberDiff line change
@@ -38,61 +38,31 @@ void array_member_access_can_remove(struct buf *bp) {
3838
bp->arr[i] = i;
3939
}
4040

41+
// rdar://138776402
4142
// CHECK-LABEL: @array_member_access_trap_on_last_iter(
42-
// CHECK-NEXT: cont1:
43-
// CHECK-NEXT: [[UPPER:%.*]] = getelementptr inbounds i8, ptr [[BP:%.*]], i64 44
44-
// CHECK-NEXT: [[ARR:%.*]] = getelementptr inbounds i8, ptr [[BP]], i64 4
43+
// CHECK-NEXT: trap:
44+
// CHECK-NEXT: [[ARR:%.*]] = getelementptr inbounds i8, ptr [[BP:%.*]], i64 4
4545
// CHECK-NEXT: store i32 0, ptr [[ARR]], align 4, {{!tbaa ![0-9]+}}
4646
// CHECK-NEXT: [[ARRAYIDX_1:%.*]] = getelementptr i8, ptr [[BP]], i64 8
47-
// CHECK-NEXT: [[TMP0:%.*]] = icmp ult ptr [[ARRAYIDX_1]], [[UPPER]], {{!annotation ![0-9]+}}
48-
// CHECK-NEXT: br i1 [[TMP0]], label [[CONT1_1:%.*]], label [[TRAP:%.*]], {{!annotation ![0-9]+}}
49-
// CHECK: trap:
50-
// CHECK-NEXT: tail call void @llvm.ubsantrap(i8 25) {{#[0-9]+}}, {{!annotation ![0-9]+}}
51-
// CHECK-NEXT: unreachable, {{!annotation ![0-9]+}}
52-
// rdar://138776402
53-
// CHECK: cont1.1:
5447
// CHECK-NEXT: store i32 1, ptr [[ARRAYIDX_1]], align 4, {{!tbaa ![0-9]+}}
5548
// CHECK-NEXT: [[ARRAYIDX_2:%.*]] = getelementptr i8, ptr [[BP]], i64 12
56-
// CHECK-NEXT: [[TMP1:%.*]] = icmp ult ptr [[ARRAYIDX_2]], [[UPPER]], {{!annotation ![0-9]+}}
57-
// CHECK-NEXT: br i1 [[TMP1]], label [[CONT1_2:%.*]], label [[TRAP]], {{!annotation ![0-9]+}}
58-
// CHECK: cont1.2:
5949
// CHECK-NEXT: store i32 2, ptr [[ARRAYIDX_2]], align 4, {{!tbaa ![0-9]+}}
6050
// CHECK-NEXT: [[ARRAYIDX_3:%.*]] = getelementptr i8, ptr [[BP]], i64 16
61-
// CHECK-NEXT: [[TMP2:%.*]] = icmp ult ptr [[ARRAYIDX_3]], [[UPPER]], {{!annotation ![0-9]+}}
62-
// CHECK-NEXT: br i1 [[TMP2]], label [[CONT1_3:%.*]], label [[TRAP]], {{!annotation ![0-9]+}}
63-
// CHECK: cont1.3:
6451
// CHECK-NEXT: store i32 3, ptr [[ARRAYIDX_3]], align 4, {{!tbaa ![0-9]+}}
6552
// CHECK-NEXT: [[ARRAYIDX_4:%.*]] = getelementptr i8, ptr [[BP]], i64 20
66-
// CHECK-NEXT: [[TMP3:%.*]] = icmp ult ptr [[ARRAYIDX_4]], [[UPPER]], {{!annotation ![0-9]+}}
67-
// CHECK-NEXT: br i1 [[TMP3]], label [[CONT1_4:%.*]], label [[TRAP]], {{!annotation ![0-9]+}}
68-
// CHECK: cont1.4:
6953
// CHECK-NEXT: store i32 4, ptr [[ARRAYIDX_4]], align 4, {{!tbaa ![0-9]+}}
7054
// CHECK-NEXT: [[ARRAYIDX_5:%.*]] = getelementptr i8, ptr [[BP]], i64 24
71-
// CHECK-NEXT: [[TMP4:%.*]] = icmp ult ptr [[ARRAYIDX_5]], [[UPPER]], {{!annotation ![0-9]+}}
72-
// CHECK-NEXT: br i1 [[TMP4]], label [[CONT1_5:%.*]], label [[TRAP]], {{!annotation ![0-9]+}}
73-
// CHECK: cont1.5:
7455
// CHECK-NEXT: store i32 5, ptr [[ARRAYIDX_5]], align 4, {{!tbaa ![0-9]+}}
7556
// CHECK-NEXT: [[ARRAYIDX_6:%.*]] = getelementptr i8, ptr [[BP]], i64 28
76-
// CHECK-NEXT: [[TMP5:%.*]] = icmp ult ptr [[ARRAYIDX_6]], [[UPPER]], {{!annotation ![0-9]+}}
77-
// CHECK-NEXT: br i1 [[TMP5]], label [[CONT1_6:%.*]], label [[TRAP]], {{!annotation ![0-9]+}}
78-
// CHECK: cont1.6:
7957
// CHECK-NEXT: store i32 6, ptr [[ARRAYIDX_6]], align 4, {{!tbaa ![0-9]+}}
8058
// CHECK-NEXT: [[ARRAYIDX_7:%.*]] = getelementptr i8, ptr [[BP]], i64 32
81-
// CHECK-NEXT: [[TMP6:%.*]] = icmp ult ptr [[ARRAYIDX_7]], [[UPPER]], {{!annotation ![0-9]+}}
82-
// CHECK-NEXT: br i1 [[TMP6]], label [[CONT1_7:%.*]], label [[TRAP]], {{!annotation ![0-9]+}}
83-
// CHECK: cont1.7:
8459
// CHECK-NEXT: store i32 7, ptr [[ARRAYIDX_7]], align 4, {{!tbaa ![0-9]+}}
8560
// CHECK-NEXT: [[ARRAYIDX_8:%.*]] = getelementptr i8, ptr [[BP]], i64 36
86-
// CHECK-NEXT: [[TMP7:%.*]] = icmp ult ptr [[ARRAYIDX_8]], [[UPPER]], {{!annotation ![0-9]+}}
87-
// CHECK-NEXT: br i1 [[TMP7]], label [[CONT1_8:%.*]], label [[TRAP]], {{!annotation ![0-9]+}}
88-
// CHECK: cont1.8:
8961
// CHECK-NEXT: store i32 8, ptr [[ARRAYIDX_8]], align 4, {{!tbaa ![0-9]+}}
9062
// CHECK-NEXT: [[ARRAYIDX_9:%.*]] = getelementptr i8, ptr [[BP]], i64 40
91-
// CHECK-NEXT: [[TMP8:%.*]] = icmp ult ptr [[ARRAYIDX_9]], [[UPPER]], {{!annotation ![0-9]+}}
92-
// CHECK-NEXT: br i1 [[TMP8]], label [[CONT1_9:%.*]], label [[TRAP]], {{!annotation ![0-9]+}}
93-
// CHECK: cont1.9:
9463
// CHECK-NEXT: store i32 9, ptr [[ARRAYIDX_9]], align 4, {{!tbaa ![0-9]+}}
95-
// CHECK-NEXT: br label [[TRAP]], {{!annotation ![0-9]+}}
64+
// CHECK-NEXT: tail call void @llvm.ubsantrap(i8 25) {{#[0-9]+}}, {{!annotation ![0-9]+}}
65+
// CHECK-NEXT: unreachable, {{!annotation ![0-9]+}}
9666
//
9767
void array_member_access_trap_on_last_iter(struct buf *bp) {
9868
for (int i = 0; i < 11; ++i)

0 commit comments

Comments
 (0)