Skip to content

Commit

Permalink
Avoid duplicate of tape size checking when there's a break stmt
Browse files Browse the repository at this point in the history
  • Loading branch information
kchristin22 committed Oct 26, 2024
1 parent b4917c0 commit 2f1deec
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 13 deletions.
21 changes: 10 additions & 11 deletions lib/Differentiator/ReverseModeVisitor.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -4055,18 +4055,16 @@ Expr* getArraySizeExpr(const ArrayType* AT, ASTContext& context,
if (isInsideLoop && !activeBreakContHandler->m_IsInvokedBySwitchStmt) {
Expr* tapeBackExprForCurrentCase =
activeBreakContHandler->CreateCFTapeBackExprForCurrentCase();
Expr* tapeSizeExprForCurrentCase =
activeBreakContHandler->CreateCFTapeSizeExprForCurrentCase();
Expr* currentBreakFlagExpr =
BuildOp(BinaryOperatorKind::BO_LAnd, tapeSizeExprForCurrentCase,
tapeBackExprForCurrentCase);
if (m_CurrentBreakFlagExpr) {
m_CurrentBreakFlagExpr =
BuildOp(BinaryOperatorKind::BO_LAnd, m_CurrentBreakFlagExpr,
currentBreakFlagExpr);

tapeBackExprForCurrentCase);
} else {
m_CurrentBreakFlagExpr = currentBreakFlagExpr;
Expr* tapeSizeExprForCurrentCase =
activeBreakContHandler->CreateCFTapeSizeExprForCurrentCase();
m_CurrentBreakFlagExpr =
BuildOp(BinaryOperatorKind::BO_LAnd, tapeSizeExprForCurrentCase,
tapeBackExprForCurrentCase);
}
}
addToCurrentBlock(pushExprToCurrentCase);
Expand Down Expand Up @@ -4147,9 +4145,10 @@ Expr* getArraySizeExpr(const ArrayType* AT, ASTContext& context,

Expr* ReverseModeVisitor::BreakContStmtHandler::
CreateCFTapeSizeExprForCurrentCase() {
return m_RMV.BuildOp(BinaryOperatorKind::BO_NE, m_ControlFlowTape->Size(),
ConstantFolder::synthesizeLiteral(
m_RMV.m_Context.IntTy, m_RMV.m_Context, 0));
return m_RMV.BuildOp(
BinaryOperatorKind::BO_NE, m_ControlFlowTape->Size(),
ConstantFolder::synthesizeLiteral(m_RMV.m_Context.IntTy,
m_RMV.m_Context, /*val=*/0));
}

void ReverseModeVisitor::BreakContStmtHandler::UpdateForwAndRevBlocks(
Expand Down
4 changes: 2 additions & 2 deletions test/Gradient/Loops.C
Original file line number Diff line number Diff line change
Expand Up @@ -2629,7 +2629,7 @@ double fn33(double i, double j) {
//CHECK-NEXT: _d_res += 1;
//CHECK-NEXT: for (;; _t0--) {
//CHECK-NEXT: {
//CHECK-NEXT: if (!_t0 || (clad::size(_t4) != 0 && clad::back(_t4) != 1 && clad::size(_t4) != 0 && clad::back(_t4) != 2)) {
//CHECK-NEXT: if (!_t0 || (clad::size(_t4) != 0 && clad::back(_t4) != 1 && clad::back(_t4) != 2)) {
//CHECK-NEXT: res = clad::pop(_t1);
//CHECK-NEXT: double _r_d0 = _d_res;
//CHECK-NEXT: _d_res = 0.;
Expand All @@ -2639,7 +2639,7 @@ double fn33(double i, double j) {
//CHECK-NEXT: if (!_t0)
//CHECK-NEXT: break;
//CHECK-NEXT: }
//CHECK-NEXT: if (clad::size(_t4) != 0 && clad::back(_t4) != 1 && clad::size(_t4) != 0 && clad::back(_t4) != 2)
//CHECK-NEXT: if (clad::size(_t4) != 0 && clad::back(_t4) != 1 && clad::back(_t4) != 2)
//CHECK-NEXT: --c;
//CHECK-NEXT: switch (clad::pop(_t4)) {
//CHECK-NEXT: case {{3U|3UL|3ULL}}:
Expand Down

0 comments on commit 2f1deec

Please sign in to comment.