Skip to content

Commit 246c0c6

Browse files
Add loop attr info to the backedge, not condition
1 parent ced23aa commit 246c0c6

File tree

4 files changed

+16
-10
lines changed

4 files changed

+16
-10
lines changed

flang/lib/Optimizer/Transforms/ControlFlowConverter.cpp

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -123,23 +123,23 @@ class CfgLoopConv : public mlir::OpRewritePattern<fir::DoLoopOp> {
123123
: terminator->operand_begin();
124124
loopCarried.append(begin, terminator->operand_end());
125125
loopCarried.push_back(itersMinusOne);
126-
rewriter.create<mlir::cf::BranchOp>(loc, conditionalBlock, loopCarried);
126+
auto backEdge = rewriter.create<mlir::cf::BranchOp>(loc, conditionalBlock, loopCarried);
127127
rewriter.eraseOp(terminator);
128128

129+
// Copy loop annotations from the do loop to the loop back edge.
130+
if (auto ann = loop.getLoopAnnotation())
131+
backEdge->setAttr("loop_annotation", *ann);
132+
129133
// Conditional block
130134
rewriter.setInsertionPointToEnd(conditionalBlock);
131135
auto zero = rewriter.create<mlir::arith::ConstantIndexOp>(loc, 0);
132136
auto comparison = rewriter.create<mlir::arith::CmpIOp>(
133137
loc, arith::CmpIPredicate::sgt, itersLeft, zero);
134138

135-
auto cond = rewriter.create<mlir::cf::CondBranchOp>(
139+
rewriter.create<mlir::cf::CondBranchOp>(
136140
loc, comparison, firstBlock, llvm::ArrayRef<mlir::Value>(), endBlock,
137141
llvm::ArrayRef<mlir::Value>());
138142

139-
// Copy loop annotations from the do loop to the loop entry condition.
140-
if (auto ann = loop.getLoopAnnotation())
141-
cond->setAttr("loop_annotation", *ann);
142-
143143
// The result of the loop operation is the values of the condition block
144144
// arguments except the induction variable on the last iteration.
145145
auto args = loop.getFinalValue()

flang/test/Fir/vector-always.fir

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,9 @@ func.func @_QPvector_always() -> i32 {
1313
%c10_i32 = arith.constant 10 : i32
1414
%c1_i32 = arith.constant 1 : i32
1515
%c10 = arith.constant 10 : index
16-
// CHECK: cf.cond_br %{{.*}}, ^{{.*}}, ^{{.*}} {loop_annotation = #[[ANNOTATION]]}
16+
// CHECK: cf.cond_br
17+
// CHECK-NOT: loop_annotation
18+
// CHECK: cf.br ^{{.*}} {loop_annotation = #[[ANNOTATION]]}
1719
%8:2 = fir.do_loop %arg0 = %c1 to %c10 step %c1 iter_args(%arg1 = %c1_i32) -> (index, i32) attributes {loopAnnotation = #loop_annotation} {
1820
fir.result %c1, %c1_i32 : index, i32
1921
}

flang/test/Integration/unroll.f90

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3,8 +3,10 @@
33
! CHECK-LABEL: unroll_dir
44
subroutine unroll_dir
55
integer :: a(10)
6-
!dir$ unroll
7-
! CHECK: br i1 {{.*}}, label {{.*}}, label {{.*}}, !llvm.loop ![[UNROLL_ENABLE_FULL_ANNO:.*]]
6+
!dir$ unroll
7+
! CHECK: br i1 {{.*}}, label {{.*}}, label {{.*}}
8+
! CHECK-NOT: !llvm.loop
9+
! CHECK: br label {{.*}}, !llvm.loop ![[UNROLL_ENABLE_FULL_ANNO:.*]]
810
do i=1,10
911
a(i)=i
1012
end do

flang/test/Integration/vector-always.f90

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,9 @@
44
subroutine vector_always
55
integer :: a(10)
66
!dir$ vector always
7-
! CHECK: br i1 {{.*}}, label {{.*}}, label {{.*}}, !llvm.loop ![[ANNOTATION:.*]]
7+
! CHECK: br i1 {{.*}}, label {{.*}}, label {{.*}}
8+
! CHECK-NOT: !llvm.loop
9+
! CHECK: br label {{.*}}, !llvm.loop ![[ANNOTATION:.*]]
810
do i=1,10
911
a(i)=i
1012
end do

0 commit comments

Comments
 (0)