Files
Ryotaro Kasuga d6abc8f78d [LoopInterchange] Use UTC as much as possible (NFC) (#202096)
Historically, the loop-interchange tests have relied heavily on checks
via pass remarks. This is because pass remarks are more human-readable
than the CHECK directives generated by UTC. However, during recent
development, I found some downsides:

- Updating them manually is a bit tedious.
- We need to carefully keep the remarks and the code consistent with
each other. In other words, we don't have any way to verify whether the
remarks themselves are reasonable.

For these reasons, I now think it makes more sense to rely on UTC as
much as possible, and this patch does that. Some tests are left as-is,
e.g., the test for checking remarks.

Disclosure: This patch is assisted-by Claude Code.
2026-06-11 07:58:29 +00:00

116 lines
5.9 KiB
LLVM

; NOTE: Assertions have been autogenerated by utils/update_test_checks.py UTC_ARGS: --version 6
; RUN: opt < %s -passes=loop-interchange -cache-line-size=64 -S | FileCheck %s
target datalayout = "e-m:e-i64:64-f80:128-n8:16:32:64-S128"
@A = common global [100 x [100 x i64]] zeroinitializer
;; for(int i=0;i<100;i++)
;; for(int j=0;j<100;j++)
;; A[j][i] = A[j][i]+k;
define void @interchange_01(i64 %k, i64 %N) !dbg !5 {
; CHECK-LABEL: define void @interchange_01(
; CHECK-SAME: i64 [[K:%.*]], i64 [[N:%.*]]) !dbg [[DBG5:![0-9]+]] {
; CHECK-NEXT: [[ENTRY:.*:]]
; CHECK-NEXT: br label %[[FOR2_PREHEADER:.*]]
; CHECK: [[FOR1_HEADER_PREHEADER:.*]]:
; CHECK-NEXT: br label %[[FOR1_HEADER:.*]]
; CHECK: [[FOR1_HEADER]]:
; CHECK-NEXT: [[J23:%.*]] = phi i64 [ [[J_NEXT24:%.*]], %[[FOR1_INC10:.*]] ], [ 0, %[[FOR1_HEADER_PREHEADER]] ]
; CHECK-NEXT: #dbg_value(i64 [[J:%.*]], [[META13:![0-9]+]], !DIExpression(), [[META14:![0-9]+]])
; CHECK-NEXT: br label %[[FOR2_SPLIT1:.*]]
; CHECK: [[FOR2_PREHEADER]]:
; CHECK-NEXT: br label %[[FOR2:.*]]
; CHECK: [[FOR2]]:
; CHECK-NEXT: [[J]] = phi i64 [ [[TMP0:%.*]], %[[FOR2_SPLIT:.*]] ], [ 0, %[[FOR2_PREHEADER]] ]
; CHECK-NEXT: br label %[[FOR1_HEADER_PREHEADER]]
; CHECK: [[FOR2_SPLIT1]]:
; CHECK-NEXT: #dbg_value(i64 [[J]], [[META13]], !DIExpression(), [[META14]])
; CHECK-NEXT: [[ARRAYIDX5:%.*]] = getelementptr inbounds [100 x [100 x i64]], ptr @A, i64 0, i64 [[J]], i64 [[J23]]
; CHECK-NEXT: [[LV:%.*]] = load i64, ptr [[ARRAYIDX5]], align 8
; CHECK-NEXT: [[ADD:%.*]] = add nsw i64 [[LV]], [[K]]
; CHECK-NEXT: store i64 [[ADD]], ptr [[ARRAYIDX5]], align 8
; CHECK-NEXT: [[J_NEXT:%.*]] = add nuw nsw i64 [[J]], 1
; CHECK-NEXT: [[EXITCOND:%.*]] = icmp eq i64 [[J]], 99
; CHECK-NEXT: #dbg_value(i64 [[J]], [[META13]], !DIExpression(), [[META14]])
; CHECK-NEXT: br label %[[FOR1_INC10]]
; CHECK: [[FOR2_SPLIT]]:
; CHECK-NEXT: [[TMP0]] = add nuw nsw i64 [[J]], 1
; CHECK-NEXT: [[TMP1:%.*]] = icmp eq i64 [[J]], 99
; CHECK-NEXT: br i1 [[TMP1]], label %[[FOR_END12:.*]], label %[[FOR2]]
; CHECK: [[FOR1_INC10]]:
; CHECK-NEXT: [[J_NEXT24]] = add nuw nsw i64 [[J23]], 1
; CHECK-NEXT: #dbg_value(i64 [[J]], [[META13]], !DIExpression(), [[META14]])
; CHECK-NEXT: [[EXITCOND26:%.*]] = icmp eq i64 [[J23]], 99
; CHECK-NEXT: br i1 [[EXITCOND26]], label %[[FOR2_SPLIT]], label %[[FOR1_HEADER]]
; CHECK: [[FOR_END12]]:
; CHECK-NEXT: ret void
;
entry:
br label %for1.header
for1.header:
%j23 = phi i64 [ 0, %entry ], [ %j.next24, %for1.inc10 ]
call void @llvm.dbg.value(metadata i64 %j, metadata !13, metadata !DIExpression()), !dbg !14
br label %for2
for2:
%j = phi i64 [ %j.next, %for2 ], [ 0, %for1.header ]
call void @llvm.dbg.value(metadata i64 %j, metadata !13, metadata !DIExpression()), !dbg !14
%arrayidx5 = getelementptr inbounds [100 x [100 x i64]], ptr @A, i64 0, i64 %j, i64 %j23
%lv = load i64, ptr %arrayidx5
%add = add nsw i64 %lv, %k
store i64 %add, ptr %arrayidx5
%j.next = add nuw nsw i64 %j, 1
%exitcond = icmp eq i64 %j, 99
call void @llvm.dbg.value(metadata i64 %j, metadata !13, metadata !DIExpression()), !dbg !14
br i1 %exitcond, label %for1.inc10, label %for2
for1.inc10:
%j.next24 = add nuw nsw i64 %j23, 1
call void @llvm.dbg.value(metadata i64 %j, metadata !13, metadata !DIExpression()), !dbg !14
%exitcond26 = icmp eq i64 %j23, 99
br i1 %exitcond26, label %for.end12, label %for1.header
for.end12:
ret void
}
; Function Attrs: nounwind readnone speculatable
declare void @llvm.dbg.value(metadata, metadata, metadata)
!llvm.dbg.cu = !{!0}
!llvm.module.flags = !{!3, !4}
!0 = distinct !DICompileUnit(language: DW_LANG_C99, file: !1, producer: "clang", isOptimized: true, runtimeVersion: 0, emissionKind: FullDebug, enums: !2)
!1 = !DIFile(filename: "test.c", directory: "/test")
!2 = !{}
!3 = !{i32 2, !"Dwarf Version", i32 4}
!4 = !{i32 2, !"Debug Info Version", i32 3}
!5 = distinct !DISubprogram(name: "foo", scope: !1, file: !1, line: 1, type: !6, isLocal: false, isDefinition: true, scopeLine: 1, flags: DIFlagPrototyped, isOptimized: true, unit: !0, retainedNodes: !12)
!6 = !DISubroutineType(types: !7)
!7 = !{null, !8, !8, !11}
!8 = !DIDerivedType(tag: DW_TAG_restrict_type, baseType: !9)
!9 = !DIDerivedType(tag: DW_TAG_pointer_type, baseType: !10, size: 32, align: 32)
!10 = !DIBasicType(name: "float", size: 32, align: 32, encoding: DW_ATE_float)
!11 = !DIBasicType(name: "int", size: 32, align: 32, encoding: DW_ATE_signed)
!12 = !{!13}
!13 = !DILocalVariable(name: "a", arg: 1, scope: !5, file: !1, line: 1, type: !8)
!14 = !DILocation(line: 1, column: 27, scope: !5)
;.
; CHECK: [[META0:![0-9]+]] = distinct !DICompileUnit(language: DW_LANG_C99, file: [[META1:![0-9]+]], producer: "clang", isOptimized: true, runtimeVersion: 0, emissionKind: FullDebug, enums: [[META2:![0-9]+]])
; CHECK: [[META1]] = !DIFile(filename: "{{.*}}test.c", directory: {{.*}})
; CHECK: [[META2]] = !{}
; CHECK: [[DBG5]] = distinct !DISubprogram(name: "foo", scope: [[META1]], file: [[META1]], line: 1, type: [[META6:![0-9]+]], scopeLine: 1, flags: DIFlagPrototyped, spFlags: DISPFlagDefinition | DISPFlagOptimized, unit: [[META0]], retainedNodes: [[META12:![0-9]+]])
; CHECK: [[META6]] = !DISubroutineType(types: [[META7:![0-9]+]])
; CHECK: [[META7]] = !{null, [[META8:![0-9]+]], [[META8]], [[META11:![0-9]+]]}
; CHECK: [[META8]] = !DIDerivedType(tag: DW_TAG_restrict_type, baseType: [[META9:![0-9]+]])
; CHECK: [[META9]] = !DIDerivedType(tag: DW_TAG_pointer_type, baseType: [[META10:![0-9]+]], size: 32, align: 32)
; CHECK: [[META10]] = !DIBasicType(name: "float", size: 32, align: 32, encoding: DW_ATE_float)
; CHECK: [[META11]] = !DIBasicType(name: "int", size: 32, align: 32, encoding: DW_ATE_signed)
; CHECK: [[META12]] = !{[[META13]]}
; CHECK: [[META13]] = !DILocalVariable(name: "a", arg: 1, scope: [[DBG5]], file: [[META1]], line: 1, type: [[META8]])
; CHECK: [[META14]] = !DILocation(line: 1, column: 27, scope: [[DBG5]])
;.