[PATCH] D86841: [clang] Add noprogress attribute deduction for infinite loops
atmnpatel updated this revision to Diff 289849. atmnpatel added a comment. In Summary: - I changed the llvm loop metadata name to `mustprogress`, to indicate that loops with this attribute are required to have side-effects. - The `mayprogress` function attribute is applied to functions where an infinite loop is found with a constant conditional. - The `mustprogress` attribute is applied to loops within a `mayprogress` function that do not have a constant conditional. Repository: rG LLVM Github Monorepo CHANGES SINCE LAST ACTION https://reviews.llvm.org/D86841/new/ https://reviews.llvm.org/D86841 Files: clang/lib/CodeGen/CGLoopInfo.cpp clang/lib/CodeGen/CGLoopInfo.h clang/lib/CodeGen/CGStmt.cpp clang/lib/CodeGen/CodeGenFunction.cpp clang/lib/CodeGen/CodeGenFunction.h clang/test/CodeGen/attr-noprogress.c clang/test/CodeGen/attr-noprogress.cpp clang/test/CodeGenCXX/fno-unroll-loops-metadata.cpp Index: clang/test/CodeGenCXX/fno-unroll-loops-metadata.cpp === --- clang/test/CodeGenCXX/fno-unroll-loops-metadata.cpp +++ clang/test/CodeGenCXX/fno-unroll-loops-metadata.cpp @@ -4,7 +4,7 @@ // RUN: %clang_cc1 -triple x86_64-apple-darwin -std=c++11 -emit-llvm -o - %s -O3 -disable-llvm-optzns -fno-unroll-loops | FileCheck --check-prefix=UNROLL_DISABLED_MD %s // RUN: %clang_cc1 -triple x86_64-apple-darwin -std=c++11 -emit-llvm -o - %s -O3 -disable-llvm-optzns | FileCheck --check-prefix=NO_UNROLL_MD %s -// NO_UNROLL_MD-NOT: llvm.loop +// NO_UNROLL_MD-NOT: llvm.loop.unroll.disable // Verify unroll.disable metadata is added to while loop with -fno-unroll-loops // and optlevel > 0. Index: clang/test/CodeGen/attr-noprogress.cpp === --- /dev/null +++ clang/test/CodeGen/attr-noprogress.cpp @@ -0,0 +1,188 @@ +// NOTE: Assertions have been autogenerated by utils/update_cc_test_checks.py UTC_ARGS: --check-attributes +// RUN: %clang_cc1 -S -emit-llvm %s -o - | FileCheck %s + +int a = 0; +int b = 0; + +// CHECK: Function Attrs: noinline nounwind optnone mayprogress +// CHECK-LABEL: @_Z2f1v( +// CHECK-NEXT: entry: +// CHECK-NEXT:br label [[FOR_COND:%.*]] +// CHECK: for.cond: +// CHECK: br i1 true, label [[FOR_BODY:%.*]], label [[FOR_END:%.*]] +// CHECK: for.body: +// CHECK: br label [[FOR_COND]] +// CHECK: for.end: +// CHECK: ret void +// +void f1() { + for (; 1;) { + } +} + +// CHECK: Function Attrs: noinline nounwind optnone +// CHECK-LABEL: @_Z2f2v( +// CHECK-NEXT: entry: +// CHECK-NEXT:br label [[FOR_COND:%.*]] +// CHECK: for.cond: +// CHECK: [[TMP0:%.*]] = load i32, i32* @a, align 4 +// CHECK: [[TMP1:%.*]] = load i32, i32* @b, align 4 +// CHECK: [[CMP:%.*]] = icmp eq i32 [[TMP0]], [[TMP1]] +// CHECK: br i1 [[CMP]], label [[FOR_BODY:%.*]], label [[FOR_END:%.*]] +// CHECK: for.body: +// CHECK: br label [[FOR_COND]] +// CHECK: for.end: +// CHECK: ret void +// +void f2() { + for (; a == b;) { + } +} + +// CHECK: Function Attrs: noinline nounwind optnone mayprogress +// CHECK-LABEL: @_Z1Fv( +// CHECK-NEXT: entry: +// CHECK-NEXT:br label [[FOR_COND:%.*]] +// CHECK: for.cond: +// CHECK: br i1 true, label [[FOR_BODY:%.*]], label [[FOR_END:%.*]] +// CHECK: for.body: +// CHECK: br label [[FOR_COND]] +// CHECK: for.end: +// CHECK: br label [[FOR_COND1:%.*]] +// CHECK: for.cond1: +// CHECK: [[TMP0:%.*]] = load i32, i32* @a, align 4 +// CHECK: [[TMP1:%.*]] = load i32, i32* @b, align 4 +// CHECK: [[CMP:%.*]] = icmp eq i32 [[TMP0]], [[TMP1]] +// CHECK: br i1 [[CMP]], label [[FOR_BODY2:%.*]], label [[FOR_END3:%.*]] +// CHECK: for.body2: +// CHECK: br label [[FOR_COND1]], !llvm.loop [[LOOP2:!.*]] +// CHECK: for.end3: +// CHECK: ret void +// +void F() { + for (; 1;) { + } + for (; a == b;) { + } +} + +// CHECK: Function Attrs: noinline nounwind optnone mayprogress +// CHECK-LABEL: @_Z2w1v( +// CHECK-NEXT: entry: +// CHECK-NEXT:br label [[WHILE_BODY:%.*]] +// CHECK: while.body: +// CHECK: br label [[WHILE_BODY]] +// +void w1() { + while (1) { + } +} + +// CHECK: Function Attrs: noinline nounwind optnone +// CHECK-LABEL: @_Z2w2v( +// CHECK-NEXT: entry: +// CHECK-NEXT:br label [[WHILE_COND:%.*]] +// CHECK: while.cond: +// CHECK: [[TMP0:%.*]] = load i32, i32* @a, align 4 +// CHECK: [[TMP1:%.*]] = load i32, i32* @b, align 4 +// CHECK: [[CMP:%.*]] = icmp eq i32 [[TMP0]], [[TMP1]] +// CHECK: br i1 [[CMP]], label [[WHILE_BODY:%.*]], label [[WHILE_END:%.*]] +// CHECK: while.body: +// CHECK: br label [[WHILE_COND]] +// CHECK: while.end: +// CHECK: ret void +// +void w2() { + while (a == b) { + } +} + +// CHECK: Function Attrs: noinline nounwind optnone mayprogress
[PATCH] D86841: [clang] Add noprogress attribute deduction for infinite loops
atmnpatel marked an inline comment as done. atmnpatel added inline comments. Comment at: clang/lib/CodeGen/CGLoopInfo.h:211 llvm::ArrayRef Attrs, const llvm::DebugLoc , -const llvm::DebugLoc ); +const llvm::DebugLoc , const bool NoProgress = false); aaron.ballman wrote: > I'd drop the top-level `const` on the declaration of `NoProgress` (that's not > a style we typically use in the project). My bad, thanks! Repository: rG LLVM Github Monorepo CHANGES SINCE LAST ACTION https://reviews.llvm.org/D86841/new/ https://reviews.llvm.org/D86841 ___ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
[PATCH] D86841: [clang] Add noprogress attribute deduction for infinite loops
atmnpatel updated this revision to Diff 289821. atmnpatel added a comment. Herald added a subscriber: zzheng. Renamed llvm loop metadata, changed deduction rules. Repository: rG LLVM Github Monorepo CHANGES SINCE LAST ACTION https://reviews.llvm.org/D86841/new/ https://reviews.llvm.org/D86841 Files: clang/lib/CodeGen/CGLoopInfo.cpp clang/lib/CodeGen/CGLoopInfo.h clang/lib/CodeGen/CGStmt.cpp clang/lib/CodeGen/CodeGenFunction.cpp clang/lib/CodeGen/CodeGenFunction.h clang/test/CodeGen/attr-noprogress.c clang/test/CodeGen/attr-noprogress.cpp clang/test/CodeGenCXX/fno-unroll-loops-metadata.cpp Index: clang/test/CodeGenCXX/fno-unroll-loops-metadata.cpp === --- clang/test/CodeGenCXX/fno-unroll-loops-metadata.cpp +++ clang/test/CodeGenCXX/fno-unroll-loops-metadata.cpp @@ -4,7 +4,7 @@ // RUN: %clang_cc1 -triple x86_64-apple-darwin -std=c++11 -emit-llvm -o - %s -O3 -disable-llvm-optzns -fno-unroll-loops | FileCheck --check-prefix=UNROLL_DISABLED_MD %s // RUN: %clang_cc1 -triple x86_64-apple-darwin -std=c++11 -emit-llvm -o - %s -O3 -disable-llvm-optzns | FileCheck --check-prefix=NO_UNROLL_MD %s -// NO_UNROLL_MD-NOT: llvm.loop +// NO_UNROLL_MD-NOT: llvm.loop.unroll.disable // Verify unroll.disable metadata is added to while loop with -fno-unroll-loops // and optlevel > 0. Index: clang/test/CodeGen/attr-noprogress.cpp === --- /dev/null +++ clang/test/CodeGen/attr-noprogress.cpp @@ -0,0 +1,188 @@ +// NOTE: Assertions have been autogenerated by utils/update_cc_test_checks.py UTC_ARGS: --check-attributes +// RUN: %clang_cc1 -S -emit-llvm %s -o - | FileCheck %s + +int a = 0; +int b = 0; + +// CHECK: Function Attrs: noinline nounwind optnone noprogress +// CHECK-LABEL: @_Z2f1v( +// CHECK-NEXT: entry: +// CHECK-NEXT:br label [[FOR_COND:%.*]] +// CHECK: for.cond: +// CHECK: br i1 true, label [[FOR_BODY:%.*]], label [[FOR_END:%.*]] +// CHECK: for.body: +// CHECK: br label [[FOR_COND]] +// CHECK: for.end: +// CHECK: ret void +// +void f1() { + for (; 1;) { + } +} + +// CHECK: Function Attrs: noinline nounwind optnone +// CHECK-LABEL: @_Z2f2v( +// CHECK-NEXT: entry: +// CHECK-NEXT:br label [[FOR_COND:%.*]] +// CHECK: for.cond: +// CHECK: [[TMP0:%.*]] = load i32, i32* @a, align 4 +// CHECK: [[TMP1:%.*]] = load i32, i32* @b, align 4 +// CHECK: [[CMP:%.*]] = icmp eq i32 [[TMP0]], [[TMP1]] +// CHECK: br i1 [[CMP]], label [[FOR_BODY:%.*]], label [[FOR_END:%.*]] +// CHECK: for.body: +// CHECK: br label [[FOR_COND]] +// CHECK: for.end: +// CHECK: ret void +// +void f2() { + for (; a == b;) { + } +} + +// CHECK: Function Attrs: noinline nounwind optnone noprogress +// CHECK-LABEL: @_Z1Fv( +// CHECK-NEXT: entry: +// CHECK-NEXT:br label [[FOR_COND:%.*]] +// CHECK: for.cond: +// CHECK: br i1 true, label [[FOR_BODY:%.*]], label [[FOR_END:%.*]] +// CHECK: for.body: +// CHECK: br label [[FOR_COND]] +// CHECK: for.end: +// CHECK: br label [[FOR_COND1:%.*]] +// CHECK: for.cond1: +// CHECK: [[TMP0:%.*]] = load i32, i32* @a, align 4 +// CHECK: [[TMP1:%.*]] = load i32, i32* @b, align 4 +// CHECK: [[CMP:%.*]] = icmp eq i32 [[TMP0]], [[TMP1]] +// CHECK: br i1 [[CMP]], label [[FOR_BODY2:%.*]], label [[FOR_END3:%.*]] +// CHECK: for.body2: +// CHECK: br label [[FOR_COND1]], !llvm.loop [[LOOP2:!.*]] +// CHECK: for.end3: +// CHECK: ret void +// +void F() { + for (; 1;) { + } + for (; a == b;) { + } +} + +// CHECK: Function Attrs: noinline nounwind optnone noprogress +// CHECK-LABEL: @_Z2w1v( +// CHECK-NEXT: entry: +// CHECK-NEXT:br label [[WHILE_BODY:%.*]] +// CHECK: while.body: +// CHECK: br label [[WHILE_BODY]] +// +void w1() { + while (1) { + } +} + +// CHECK: Function Attrs: noinline nounwind optnone +// CHECK-LABEL: @_Z2w2v( +// CHECK-NEXT: entry: +// CHECK-NEXT:br label [[WHILE_COND:%.*]] +// CHECK: while.cond: +// CHECK: [[TMP0:%.*]] = load i32, i32* @a, align 4 +// CHECK: [[TMP1:%.*]] = load i32, i32* @b, align 4 +// CHECK: [[CMP:%.*]] = icmp eq i32 [[TMP0]], [[TMP1]] +// CHECK: br i1 [[CMP]], label [[WHILE_BODY:%.*]], label [[WHILE_END:%.*]] +// CHECK: while.body: +// CHECK: br label [[WHILE_COND]] +// CHECK: while.end: +// CHECK: ret void +// +void w2() { + while (a == b) { + } +} + +// CHECK: Function Attrs: noinline nounwind optnone noprogress +// CHECK-LABEL: @_Z1Wv( +// CHECK-NEXT: entry: +// CHECK-NEXT:br label [[WHILE_COND:%.*]] +// CHECK: while.cond: +// CHECK: [[TMP0:%.*]] = load i32, i32* @a, align 4 +// CHECK: [[TMP1:%.*]] = load i32, i32* @b, align 4 +// CHECK: [[CMP:%.*]] = icmp eq i32 [[TMP0]], [[TMP1]] +//
[PATCH] D86841: [clang] Add noprogress attribute deduction for infinite loops
aaron.ballman added inline comments. Comment at: clang/lib/CodeGen/CGLoopInfo.h:211 llvm::ArrayRef Attrs, const llvm::DebugLoc , -const llvm::DebugLoc ); +const llvm::DebugLoc , const bool NoProgress = false); I'd drop the top-level `const` on the declaration of `NoProgress` (that's not a style we typically use in the project). Repository: rG LLVM Github Monorepo CHANGES SINCE LAST ACTION https://reviews.llvm.org/D86841/new/ https://reviews.llvm.org/D86841 ___ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits