diff --git a/lib/Differentiator/ReverseModeVisitor.cpp b/lib/Differentiator/ReverseModeVisitor.cpp index 089c421de..ca89dc34a 100644 --- a/lib/Differentiator/ReverseModeVisitor.cpp +++ b/lib/Differentiator/ReverseModeVisitor.cpp @@ -800,14 +800,42 @@ Expr* getArraySizeExpr(const ArrayType* AT, ASTContext& context, // to this scope. beginScope(Scope::DeclScope | Scope::ControlScope); - StmtDiff cond = Clone(If->getCond()); // Condition has to be stored as a "global" variable, to take the correct // branch in the reverse pass. // If we are inside loop, the condition has to be stored in a stack after // the if statement. Expr* PushCond = nullptr; Expr* PopCond = nullptr; - auto condExpr = Visit(cond.getExpr()); + // Create a block "around" if statement, e.g: + // { + // ... + // if (...) {...} + // } + beginBlock(direction::forward); + beginBlock(direction::reverse); + StmtDiff condDiff; + // if the statement has an init, we process it + if (If->hasInitStorage()) { + StmtDiff initDiff = Visit(If->getInit()); + addToCurrentBlock(initDiff.getStmt(), direction::forward); + addToCurrentBlock(initDiff.getStmt_dx(), direction::reverse); + } + // this ensures we can differentiate conditions that affect the derivatives + // as well as declarations inside the condition: + beginBlock(direction::reverse); + if (const auto* condDeclStmt = If->getConditionVariableDeclStmt()) + condDiff = Visit(condDeclStmt); + else + condDiff = Visit(If->getCond()); + CompoundStmt* RCS = endBlock(direction::reverse); + if (!RCS->body_empty()) { + std::reverse( + RCS->body_begin(), + RCS->body_end()); // it is reversed in the endBlock() but we don't + // actually need this, so we reverse it once again + addToCurrentBlock(RCS, direction::reverse); + } + if (isInsideLoop) { // If we are inside for loop, cond will be stored in the following way: // forward: @@ -820,17 +848,20 @@ Expr* getArraySizeExpr(const ArrayType* AT, ASTContext& context, // if (clad::push(..., _t) { ... } // is incorrect when if contains return statement inside: return will // skip corresponding push. - cond = StoreAndRef(condExpr.getExpr(), direction::forward, "_t", - /*forceDeclCreation=*/true); - StmtDiff condPushPop = GlobalStoreAndRef(cond.getExpr(), "_cond", - /*force=*/true); + condDiff = StoreAndRef(condDiff.getExpr(), m_Context.BoolTy, + direction::forward, "_t", + /*forceDeclCreation=*/true); + StmtDiff condPushPop = + GlobalStoreAndRef(condDiff.getExpr(), m_Context.BoolTy, "_cond", + /*force=*/true); PushCond = condPushPop.getExpr(); PopCond = condPushPop.getExpr_dx(); } else - cond = GlobalStoreAndRef(condExpr.getExpr(), "_cond"); + condDiff = + GlobalStoreAndRef(condDiff.getExpr(), m_Context.BoolTy, "_cond"); // Convert cond to boolean condition. We are modifying each Stmt in // StmtDiff. - for (Stmt*& S : cond.getBothStmts()) + for (Stmt*& S : condDiff.getBothStmts()) if (S) S = m_Sema .ActOnCondition(getCurrentScope(), noLoc, cast(S), @@ -838,44 +869,6 @@ Expr* getArraySizeExpr(const ArrayType* AT, ASTContext& context, .get() .second; - // Create a block "around" if statement, e.g: - // { - // ... - // if (...) {...} - // } - beginBlock(direction::forward); - beginBlock(direction::reverse); - const Stmt* init = If->getInit(); - StmtDiff initResult = init ? Visit(init) : StmtDiff{}; - // If there is Init, it's derivative will be output in the block before if: - // E.g., for: - // if (int x = 1; ...) {...} - // result will be: - // { - // int _d_x = 0; - // if (int x = 1; ...) {...} - // } - // This is done to avoid variable names clashes. - addToCurrentBlock(initResult.getStmt_dx()); - - VarDecl* condVarClone = nullptr; - if (const VarDecl* condVarDecl = If->getConditionVariable()) { - DeclDiff condVarDeclDiff = DifferentiateVarDecl(condVarDecl); - condVarClone = condVarDeclDiff.getDecl(); - if (condVarDeclDiff.getDecl_dx()) - addToBlock(BuildDeclStmt(condVarDeclDiff.getDecl_dx()), m_Globals); - } - - // Condition is just cloned as it is, not derived. - // FIXME: if condition changes one of the variables, it may be reasonable - // to derive it, e.g. - // if (x += x) {...} - // should result in: - // { - // _d_y += _d_x - // if (y += x) {...} - // } - auto VisitBranch = [&](const Stmt* Branch) -> StmtDiff { if (!Branch) return {}; @@ -902,37 +895,20 @@ Expr* getArraySizeExpr(const ArrayType* AT, ASTContext& context, StmtDiff thenDiff = VisitBranch(If->getThen()); StmtDiff elseDiff = VisitBranch(If->getElse()); - // It is problematic to specify both condVarDecl and cond thorugh - // Sema::ActOnIfStmt, therefore we directly use the IfStmt constructor. - Stmt* Forward = clad_compat::IfStmt_Create(m_Context, - noLoc, - If->isConstexpr(), - initResult.getStmt(), - condVarClone, - cond.getExpr(), - noLoc, - noLoc, - thenDiff.getStmt(), - noLoc, - elseDiff.getStmt()); + Stmt* Forward = clad_compat::IfStmt_Create( + m_Context, noLoc, If->isConstexpr(), nullptr, nullptr, + condDiff.getExpr(), noLoc, noLoc, thenDiff.getStmt(), noLoc, + elseDiff.getStmt()); addToCurrentBlock(Forward, direction::forward); - Expr* reverseCond = cond.getExpr_dx(); + Expr* reverseCond = condDiff.getExpr_dx(); if (isInsideLoop) { addToCurrentBlock(PushCond, direction::forward); reverseCond = PopCond; } - Stmt* Reverse = clad_compat::IfStmt_Create(m_Context, - noLoc, - If->isConstexpr(), - initResult.getStmt_dx(), - condVarClone, - reverseCond, - noLoc, - noLoc, - thenDiff.getStmt_dx(), - noLoc, - elseDiff.getStmt_dx()); + Stmt* Reverse = clad_compat::IfStmt_Create( + m_Context, noLoc, If->isConstexpr(), nullptr, nullptr, reverseCond, + noLoc, noLoc, thenDiff.getStmt_dx(), noLoc, elseDiff.getStmt_dx()); addToCurrentBlock(Reverse, direction::reverse); CompoundStmt* ForwardBlock = endBlock(direction::forward); CompoundStmt* ReverseBlock = endBlock(direction::reverse); diff --git a/test/ErrorEstimation/ConditonalStatements.C b/test/ErrorEstimation/ConditonalStatements.C index 1f9108d36..db91578fd 100644 --- a/test/ErrorEstimation/ConditonalStatements.C +++ b/test/ErrorEstimation/ConditonalStatements.C @@ -25,6 +25,7 @@ float func(float x, float y) { //CHECK-NEXT: float _t1; //CHECK-NEXT: float _t2; //CHECK-NEXT: double _ret_value0 = 0; +//CHECK-NEXT: { //CHECK-NEXT: _cond0 = x > y; //CHECK-NEXT: if (_cond0) { //CHECK-NEXT: _t0 = y; @@ -36,6 +37,7 @@ float func(float x, float y) { //CHECK-NEXT: _t2 = x; //CHECK-NEXT: x = y; //CHECK-NEXT: } +//CHECK-NEXT: } //CHECK-NEXT: _ret_value0 = x + y; //CHECK-NEXT: goto _label0; //CHECK-NEXT: _label0: @@ -91,6 +93,7 @@ float func2(float x) { //CHECK-NEXT: bool _cond0; //CHECK-NEXT: double _ret_value0 = 0; //CHECK-NEXT: float z = x * x; +//CHECK-NEXT: { //CHECK-NEXT: _cond0 = z > 9; //CHECK-NEXT: if (_cond0) { //CHECK-NEXT: _ret_value0 = x + x; @@ -99,6 +102,7 @@ float func2(float x) { //CHECK-NEXT: _ret_value0 = x * x; //CHECK-NEXT: goto _label1; //CHECK-NEXT: } +//CHECK-NEXT: } //CHECK-NEXT: if (_cond0) //CHECK-NEXT: _label0: //CHECK-NEXT: { diff --git a/test/Gradient/Assignments.C b/test/Gradient/Assignments.C index 4dce006c3..c6542b09a 100644 --- a/test/Gradient/Assignments.C +++ b/test/Gradient/Assignments.C @@ -38,10 +38,12 @@ double f2(double x, double y) { //CHECK: void f2_grad(double x, double y, double *_d_x, double *_d_y) { //CHECK-NEXT: bool _cond0; //CHECK-NEXT: double _t0; -//CHECK-NEXT: _cond0 = x < y; -//CHECK-NEXT: if (_cond0) { -//CHECK-NEXT: _t0 = x; -//CHECK-NEXT: x = y; +//CHECK-NEXT: { +//CHECK-NEXT: _cond0 = x < y; +//CHECK-NEXT: if (_cond0) { +//CHECK-NEXT: _t0 = x; +//CHECK-NEXT: x = y; +//CHECK-NEXT: } //CHECK-NEXT: } //CHECK-NEXT: goto _label0; //CHECK-NEXT: _label0: @@ -160,18 +162,22 @@ double f5(double x, double y) { //CHECK-NEXT: double z = 0; //CHECK-NEXT: double _t1; //CHECK-NEXT: double t = x * x; +//CHECK-NEXT: { //CHECK-NEXT: _cond0 = x < 0; //CHECK-NEXT: if (_cond0) { //CHECK-NEXT: _t0 = t; //CHECK-NEXT: t = -t; //CHECK-NEXT: goto _label0; //CHECK-NEXT: } +//CHECK-NEXT: } +//CHECK-NEXT: { //CHECK-NEXT: _cond1 = y < 0; //CHECK-NEXT: if (_cond1) { //CHECK-NEXT: z = t; //CHECK-NEXT: _t1 = t; //CHECK-NEXT: t = -t; //CHECK-NEXT: } +//CHECK-NEXT: } //CHECK-NEXT: goto _label1; //CHECK-NEXT: _label1: //CHECK-NEXT: _d_t += 1; @@ -223,18 +229,22 @@ double f6(double x, double y) { //CHECK-NEXT: double z = 0; //CHECK-NEXT: double _t1; //CHECK-NEXT: double t = x * x; +//CHECK-NEXT: { //CHECK-NEXT: _cond0 = x < 0; //CHECK-NEXT: if (_cond0) { //CHECK-NEXT: _t0 = t; //CHECK-NEXT: t = -t; //CHECK-NEXT: goto _label0; //CHECK-NEXT: } +//CHECK-NEXT: } +//CHECK-NEXT: { //CHECK-NEXT: _cond1 = y < 0; //CHECK-NEXT: if (_cond1) { //CHECK-NEXT: z = t; //CHECK-NEXT: _t1 = t; //CHECK-NEXT: t = -t; //CHECK-NEXT: } +//CHECK-NEXT: } //CHECK-NEXT: goto _label1; //CHECK-NEXT: _label1: //CHECK-NEXT: _d_t += 1; diff --git a/test/Gradient/FunctionCalls.C b/test/Gradient/FunctionCalls.C index a3af2a557..cffff026d 100644 --- a/test/Gradient/FunctionCalls.C +++ b/test/Gradient/FunctionCalls.C @@ -915,9 +915,11 @@ double sq_defined_later(double x) { // CHECK: void check_and_return_pullback(double x, char c, const char *s, double _d_y, double *_d_x, char *_d_c, char *_d_s) { // CHECK-NEXT: bool _cond0; +// CHECK-NEXT: { // CHECK-NEXT: _cond0 = c == 'a' && s[0] == 'a'; // CHECK-NEXT: if (_cond0) // CHECK-NEXT: goto _label0; +// CHECK-NEXT: } // CHECK-NEXT: goto _label1; // CHECK-NEXT: _label1: // CHECK-NEXT: ; @@ -957,9 +959,11 @@ double sq_defined_later(double x) { //CHECK: void recFun_pullback(double x, double y, double _d_y0, double *_d_x, double *_d_y) { //CHECK-NEXT: bool _cond0; +//CHECK-NEXT: { //CHECK-NEXT: _cond0 = x > y; //CHECK-NEXT: if (_cond0) //CHECK-NEXT: goto _label0; +//CHECK-NEXT: } //CHECK-NEXT: goto _label1; //CHECK-NEXT: _label1: //CHECK-NEXT: { diff --git a/test/Gradient/Gradients.C b/test/Gradient/Gradients.C index d2b1ea23f..fc374912b 100644 --- a/test/Gradient/Gradients.C +++ b/test/Gradient/Gradients.C @@ -1,4 +1,4 @@ -// RUN: %cladnumdiffclang %s -I%S/../../include -oGradients.out 2>&1 | FileCheck %s +// RUN: %cladnumdiffclang %s -std=c++17 -I%S/../../include -oGradients.out 2>&1 | FileCheck %s // RUN: ./Gradients.out | FileCheck -check-prefix=CHECK-EXEC %s // RUN: %cladnumdiffclang -Xclang -plugin-arg-clad -Xclang -enable-tbr %s -I%S/../../include -oGradients.out // RUN: ./Gradients.out | FileCheck -check-prefix=CHECK-EXEC %s @@ -297,11 +297,13 @@ double f_cond4(double x, double y) { //CHECK-NEXT: double _t0; //CHECK-NEXT: int i = 0; //CHECK-NEXT: double arr[2] = {x, y}; +//CHECK-NEXT: { //CHECK-NEXT: _cond0 = x > 0; //CHECK-NEXT: if (_cond0) { //CHECK-NEXT: _t0 = y; //CHECK-NEXT: y = arr[i] * x; //CHECK-NEXT: } +//CHECK-NEXT: } //CHECK-NEXT: goto _label0; //CHECK-NEXT: _label0: //CHECK-NEXT: *_d_y += 1; @@ -331,11 +333,13 @@ double f_if1(double x, double y) { //CHECK: void f_if1_grad(double x, double y, double *_d_x, double *_d_y) { //CHECK-NEXT: bool _cond0; +//CHECK-NEXT: { //CHECK-NEXT: _cond0 = x > y; //CHECK-NEXT: if (_cond0) //CHECK-NEXT: goto _label0; //CHECK-NEXT: else //CHECK-NEXT: goto _label1; +//CHECK-NEXT: } //CHECK-NEXT: if (_cond0) //CHECK-NEXT: _label0: //CHECK-NEXT: *_d_x += 1; @@ -358,6 +362,7 @@ double f_if2(double x, double y) { //CHECK: void f_if2_grad(double x, double y, double *_d_x, double *_d_y) { //CHECK-NEXT: bool _cond0; //CHECK-NEXT: bool _cond1; +//CHECK-NEXT: { //CHECK-NEXT: _cond0 = x > y; //CHECK-NEXT: if (_cond0) //CHECK-NEXT: goto _label0; @@ -368,6 +373,7 @@ double f_if2(double x, double y) { //CHECK-NEXT: else //CHECK-NEXT: goto _label2; //CHECK-NEXT: } +//CHECK-NEXT: } //CHECK-NEXT: if (_cond0) //CHECK-NEXT: _label0: //CHECK-NEXT: *_d_x += 1; @@ -584,6 +590,7 @@ void f_decls3_grad(double x, double y, double *_d_x, double *_d_y); //CHECK-NEXT: double _d_b = 0; //CHECK-NEXT: double a = 3 * x; //CHECK-NEXT: double c = 333 * y; +//CHECK-NEXT: { //CHECK-NEXT: _cond0 = x > 1; //CHECK-NEXT: if (_cond0) //CHECK-NEXT: goto _label0; @@ -592,6 +599,7 @@ void f_decls3_grad(double x, double y, double *_d_x, double *_d_y); //CHECK-NEXT: if (_cond1) //CHECK-NEXT: goto _label1; //CHECK-NEXT: } +//CHECK-NEXT: } //CHECK-NEXT: double b = a * a; //CHECK-NEXT: goto _label2; //CHECK-NEXT: _label2: @@ -790,6 +798,109 @@ double fn_div(double x) { // CHECK-NEXT: } // CHECK-NEXT: } +double fn_cond_decl(double x, double y) { + int flag = 1; + if (int cond = flag) + return y*y; + return x*x + y*y; +} // = y^2 + +//CHECK: void fn_cond_decl_grad(double x, double y, double *_d_x, double *_d_y) { +//CHECK-NEXT: int _d_flag = 0; +//CHECK-NEXT: int _d_cond = 0; +//CHECK-NEXT: int cond = 0; +//CHECK-NEXT: bool _cond0; +//CHECK-NEXT: int flag = 1; +//CHECK-NEXT: { +//CHECK-NEXT: _cond0 = cond = flag; +//CHECK-NEXT: if (_cond0) +//CHECK-NEXT: goto _label0; +//CHECK-NEXT: } +//CHECK-NEXT: goto _label1; +//CHECK-NEXT: _label1: +//CHECK-NEXT: { +//CHECK-NEXT: *_d_x += 1 * x; +//CHECK-NEXT: *_d_x += x * 1; +//CHECK-NEXT: *_d_y += 1 * y; +//CHECK-NEXT: *_d_y += y * 1; +//CHECK-NEXT: } +//CHECK-NEXT: { +//CHECK-NEXT: if (_cond0) +//CHECK-NEXT: _label0: +//CHECK-NEXT: { +//CHECK-NEXT: *_d_y += 1 * y; +//CHECK-NEXT: *_d_y += y * 1; +//CHECK-NEXT: } +//CHECK-NEXT: { +//CHECK-NEXT: _d_flag += _d_cond; +//CHECK-NEXT: } +//CHECK-NEXT: } +//CHECK-NEXT: } + +double fn_cond_side_eff(double x) { + if (x += x) { + return x; + } + return x; +} // = 2x + +//CHECK: void fn_cond_side_eff_grad(double x, double *_d_x) { +//CHECK-NEXT: double _t0; +//CHECK-NEXT: bool _cond0; +//CHECK-NEXT: { +//CHECK-NEXT: _t0 = x; +//CHECK-NEXT: _cond0 = x += x; +//CHECK-NEXT: if (_cond0) { +//CHECK-NEXT: goto _label0; +//CHECK-NEXT: } +//CHECK-NEXT: } +//CHECK-NEXT: goto _label1; +//CHECK-NEXT: _label1: +//CHECK-NEXT: *_d_x += 1; +//CHECK-NEXT: { +//CHECK-NEXT: if (_cond0) { +//CHECK-NEXT: _label0: +//CHECK-NEXT: *_d_x += 1; +//CHECK-NEXT: } +//CHECK-NEXT: { +//CHECK-NEXT: x = _t0; +//CHECK-NEXT: double _r_d0 = *_d_x; +//CHECK-NEXT: *_d_x += _r_d0; +//CHECK-NEXT: } +//CHECK-NEXT: } +//CHECK-NEXT: } + +double fn_cond_init(double x) { + if (int a = 12; a <= 0) { + return x+x*x; + } + return x; +} // = x + +//CHECK: void fn_cond_init_grad(double x, double *_d_x) { +//CHECK-NEXT: int _d_a = 0; +//CHECK-NEXT: int a = 0; +//CHECK-NEXT: bool _cond0; +//CHECK-NEXT: { +//CHECK-NEXT: a = 12; +//CHECK-NEXT: _cond0 = a <= 0; +//CHECK-NEXT: if (_cond0) { +//CHECK-NEXT: goto _label0; +//CHECK-NEXT: } +//CHECK-NEXT: } +//CHECK-NEXT: goto _label1; +//CHECK-NEXT: _label1: +//CHECK-NEXT: *_d_x += 1; +//CHECK-NEXT: if (_cond0) { +//CHECK-NEXT: _label0: +//CHECK-NEXT: { +//CHECK-NEXT: *_d_x += 1; +//CHECK-NEXT: *_d_x += 1 * x; +//CHECK-NEXT: *_d_x += x * 1; +//CHECK-NEXT: } +//CHECK-NEXT: } +//CHECK-NEXT: } + #define TEST(F, x, y) \ { \ result[0] = 0; \ @@ -850,4 +961,14 @@ int main() { INIT_GRADIENT(fn_div); dx = 0; TEST_GRADIENT(fn_div, /*numOfDerivativeArgs=*/1, 2, &dx); // CHECK-EXEC: 0.12 + + INIT_GRADIENT(fn_cond_decl); + + INIT_GRADIENT(fn_cond_side_eff); + TEST_GRADIENT(fn_cond_side_eff, /*numOfDerivativeArgs=*/1, 0, &dx); // CHECK-EXEC: 2.00 + TEST_GRADIENT(fn_cond_side_eff, /*numOfDerivativeArgs=*/1, 1, &dx); // CHECK-EXEC: 2.00 + + INIT_GRADIENT(fn_cond_init); + TEST_GRADIENT(fn_cond_init, /*numOfDerivativeArgs=*/1, 0, &dx); // CHECK-EXEC: 1.00 + TEST_GRADIENT(fn_cond_init, /*numOfDerivativeArgs=*/1, -1, &dx); // CHECK-EXEC: 1.00 } diff --git a/test/Gradient/Loops.C b/test/Gradient/Loops.C index 1051bff9e..0c3690e64 100644 --- a/test/Gradient/Loops.C +++ b/test/Gradient/Loops.C @@ -115,8 +115,8 @@ double f3(double x) { //CHECK-NEXT: _t0++; //CHECK-NEXT: clad::push(_t1, t); //CHECK-NEXT: t *= x; -//CHECK-NEXT: bool _t2 = i == 1; //CHECK-NEXT: { +//CHECK-NEXT: bool _t2 = i == 1; //CHECK-NEXT: if (_t2) //CHECK-NEXT: goto _label0; //CHECK-NEXT: clad::push(_t3, _t2); @@ -999,8 +999,8 @@ double fn14(double i, double j) { // CHECK-NEXT: while (choice--) // CHECK-NEXT: { // CHECK-NEXT: _t0++; -// CHECK-NEXT: bool _t1 = choice > 3; // CHECK-NEXT: { +// CHECK-NEXT: bool _t1 = choice > 3; // CHECK-NEXT: if (_t1) { // CHECK-NEXT: clad::push(_t3, res); // CHECK-NEXT: res += i; @@ -1011,8 +1011,8 @@ double fn14(double i, double j) { // CHECK-NEXT: } // CHECK-NEXT: clad::push(_t2, _t1); // CHECK-NEXT: } -// CHECK-NEXT: bool _t5 = choice > 1; // CHECK-NEXT: { +// CHECK-NEXT: bool _t5 = choice > 1; // CHECK-NEXT: if (_t5) { // CHECK-NEXT: clad::push(_t7, res); // CHECK-NEXT: res += j; @@ -1023,8 +1023,8 @@ double fn14(double i, double j) { // CHECK-NEXT: } // CHECK-NEXT: clad::push(_t6, _t5); // CHECK-NEXT: } -// CHECK-NEXT: bool _t8 = choice > 0; // CHECK-NEXT: { +// CHECK-NEXT: bool _t8 = choice > 0; // CHECK-NEXT: if (_t8) { // CHECK-NEXT: clad::push(_t10, res); // CHECK-NEXT: res += i * j; @@ -1119,8 +1119,8 @@ double fn15(double i, double j) { // CHECK-NEXT: while (choice--) // CHECK-NEXT: { // CHECK-NEXT: _t0++; -// CHECK-NEXT: bool _t1 = choice > 2; // CHECK-NEXT: { +// CHECK-NEXT: bool _t1 = choice > 2; // CHECK-NEXT: if (_t1) { // CHECK-NEXT: clad::push(_t3, {{1U|1UL}}); // CHECK-NEXT: continue; @@ -1132,8 +1132,8 @@ double fn15(double i, double j) { // CHECK-NEXT: while (another_choice--) // CHECK-NEXT: { // CHECK-NEXT: clad::back(_t5)++; -// CHECK-NEXT: bool _t6 = another_choice > 1; // CHECK-NEXT: { +// CHECK-NEXT: bool _t6 = another_choice > 1; // CHECK-NEXT: if (_t6) { // CHECK-NEXT: clad::push(_t8, res); // CHECK-NEXT: res += i; @@ -1144,8 +1144,8 @@ double fn15(double i, double j) { // CHECK-NEXT: } // CHECK-NEXT: clad::push(_t7, _t6); // CHECK-NEXT: } -// CHECK-NEXT: bool _t10 = another_choice > 0; // CHECK-NEXT: { +// CHECK-NEXT: bool _t10 = another_choice > 0; // CHECK-NEXT: if (_t10) { // CHECK-NEXT: clad::push(_t12, res); // CHECK-NEXT: res += j; @@ -1237,8 +1237,8 @@ double fn16(double i, double j) { // CHECK-NEXT: _t0 = 0; // CHECK-NEXT: for (ii = 0; ii < counter; ++ii) { // CHECK-NEXT: _t0++; -// CHECK-NEXT: bool _t1 = ii == 4; // CHECK-NEXT: { +// CHECK-NEXT: bool _t1 = ii == 4; // CHECK-NEXT: if (_t1) { // CHECK-NEXT: clad::push(_t3, res); // CHECK-NEXT: res += i * j; @@ -1249,8 +1249,8 @@ double fn16(double i, double j) { // CHECK-NEXT: } // CHECK-NEXT: clad::push(_t2, _t1); // CHECK-NEXT: } -// CHECK-NEXT: bool _t5 = ii > 2; // CHECK-NEXT: { +// CHECK-NEXT: bool _t5 = ii > 2; // CHECK-NEXT: if (_t5) { // CHECK-NEXT: clad::push(_t7, res); // CHECK-NEXT: res += 2 * i; @@ -1343,8 +1343,8 @@ double fn17(double i, double j) { // CHECK-NEXT: for (ii = 0; ii < counter; ++ii) { // CHECK-NEXT: _t0++; // CHECK-NEXT: clad::push(_t1, jj) , jj = ii; -// CHECK-NEXT: bool _t2 = ii < 2; // CHECK-NEXT: { +// CHECK-NEXT: bool _t2 = ii < 2; // CHECK-NEXT: if (_t2) { // CHECK-NEXT: clad::push(_t4, {{1U|1UL}}); // CHECK-NEXT: continue; @@ -1355,8 +1355,8 @@ double fn17(double i, double j) { // CHECK-NEXT: while (jj--) // CHECK-NEXT: { // CHECK-NEXT: clad::back(_t5)++; -// CHECK-NEXT: bool _t6 = jj < 3; // CHECK-NEXT: { +// CHECK-NEXT: bool _t6 = jj < 3; // CHECK-NEXT: if (_t6) { // CHECK-NEXT: clad::push(_t8, res); // CHECK-NEXT: res += i * j; @@ -1460,14 +1460,13 @@ double fn18(double i, double j) { // CHECK-NEXT: _t0 = 0; // CHECK-NEXT: for (counter = 0; counter < choice; ++counter) { // CHECK-NEXT: _t0++; -// CHECK-NEXT: bool _t1 = counter < 2; // CHECK-NEXT: { +// CHECK-NEXT: bool _t1 = counter < 2; // CHECK-NEXT: if (_t1) { // CHECK-NEXT: clad::push(_t3, res); // CHECK-NEXT: res += i + j; // CHECK-NEXT: } else { // CHECK-NEXT: bool _t4 = counter < 4; -// CHECK-NEXT: { // CHECK-NEXT: if (_t4) { // CHECK-NEXT: clad::push(_t6, {{1U|1UL}}); // CHECK-NEXT: continue; @@ -1480,7 +1479,6 @@ double fn18(double i, double j) { // CHECK-NEXT: } // CHECK-NEXT: } // CHECK-NEXT: clad::push(_t5, _t4); -// CHECK-NEXT: } // CHECK-NEXT: } // CHECK-NEXT: clad::push(_t2, _t1); // CHECK-NEXT: } diff --git a/test/Hessian/BuiltinDerivatives.C b/test/Hessian/BuiltinDerivatives.C index 0e0adbdbc..533c80a9b 100644 --- a/test/Hessian/BuiltinDerivatives.C +++ b/test/Hessian/BuiltinDerivatives.C @@ -383,13 +383,14 @@ int main() { // CHECK-NEXT: float _d_val = 0; // CHECK-NEXT: float _t0; // CHECK-NEXT: float _d_derivative = 0; -// CHECK-NEXT: float _cond0; +// CHECK-NEXT: bool _cond0; // CHECK-NEXT: float _t1; // CHECK-NEXT: float _t2; // CHECK-NEXT: float _t3; // CHECK-NEXT: float val = ::std::pow(x, exponent); // CHECK-NEXT: _t0 = ::std::pow(x, exponent - 1); // CHECK-NEXT: float derivative = (exponent * _t0) * d_x; +// CHECK-NEXT: { // CHECK-NEXT: _cond0 = d_exponent; // CHECK-NEXT: if (_cond0) { // CHECK-NEXT: _t1 = derivative; @@ -397,6 +398,7 @@ int main() { // CHECK-NEXT: _t2 = ::std::log(x); // CHECK-NEXT: derivative += (_t3 * _t2) * d_exponent; // CHECK-NEXT: } +// CHECK-NEXT: } // CHECK-NEXT: goto _label0; // CHECK-NEXT: _label0: // CHECK-NEXT: { diff --git a/test/NumericalDiff/NumDiff.C b/test/NumericalDiff/NumDiff.C index c65ff8a39..a3b118757 100644 --- a/test/NumericalDiff/NumDiff.C +++ b/test/NumericalDiff/NumDiff.C @@ -43,11 +43,13 @@ double test_3(double x) { //CHECK-NEXT: bool _cond0; //CHECK-NEXT: double _d_constant = 0; //CHECK-NEXT: double constant = 0; +//CHECK-NEXT: { //CHECK-NEXT: _cond0 = x > 0; //CHECK-NEXT: if (_cond0) { //CHECK-NEXT: constant = 11.; //CHECK-NEXT: goto _label0; //CHECK-NEXT: } +//CHECK-NEXT: } //CHECK-NEXT: goto _label1; //CHECK-NEXT: _label1: //CHECK-NEXT: ;