Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[AST] Do not reorder non-constant operands #962

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
26 changes: 26 additions & 0 deletions test/llvm_ir_correct/short-circuit-eval.f90
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
!
! Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
! See https://llvm.org/LICENSE.txt for license information.
! SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
!

! Check that short-circuit evaluation of logical expressions work as expected.
! The two operands should not be reordered if neither is constant.
!
! RUN: %flang -S %s -emit-llvm -o - | FileCheck %s
!
! CHECK: [[y8:%[0-9]+]] = bitcast i64* %y to i8*
! CHECK: [[LOP:%[0-9]+]] = icmp eq i8* [[y8]], null
! CHECK: br i1 [[LOP]], label %L.[[SHORTCUT:.*]], label %L.[[ROP:.*]],
! CHECK: L.[[ROP]]:
! CHECK: [[y32:%[0-9]+]] = bitcast i64* %y to i32*
! CHECK: load i32, i32* [[y32]]
! CHECK: L.[[SHORTCUT]]:

subroutine setoptional(x, y)
integer :: x
integer, intent(inout), optional ::y
if (present(y) .and. y == 10) then
y = x
end if
end subroutine setoptional
4 changes: 0 additions & 4 deletions tools/flang1/flang1exe/ast.c
Original file line number Diff line number Diff line change
Expand Up @@ -739,10 +739,6 @@ mk_binop(int optype, int lop, int rop, DTYPE dtype)
rop = tmp;
c2 = c1;
c1 = 0;
} else if (ncons == 0 && lop > rop) {
tmp = lop;
lop = rop;
rop = tmp;
}
}
break;
Expand Down