summaryrefslogtreecommitdiff
path: root/flang
diff options
context:
space:
mode:
authorPeter Steinfeld <psteinfeld@nvidia.com>2021-06-18 19:18:27 -0700
committerPeter Steinfeld <psteinfeld@nvidia.com>2021-06-20 07:25:05 -0700
commite7f78fb9171768a514611304caf42eb034ec9247 (patch)
tree744e3407f0f507647955e677d328da9adddc82dd /flang
parent240acb0cff3f7a5b33e29ad7df2081dd9140d630 (diff)
downloadllvm-e7f78fb9171768a514611304caf42eb034ec9247.tar.gz
[flang] Implement constant folding for the NOT intrinsic
I implemented constant folding for the NOT intrinsic and added some tests. Differential Revision: https://reviews.llvm.org/D104587
Diffstat (limited to 'flang')
-rw-r--r--flang/lib/Evaluate/fold-integer.cpp5
-rw-r--r--flang/test/Evaluate/folding01.f904
2 files changed, 8 insertions, 1 deletions
diff --git a/flang/lib/Evaluate/fold-integer.cpp b/flang/lib/Evaluate/fold-integer.cpp
index 19b9f9293e51..01f30b085a56 100644
--- a/flang/lib/Evaluate/fold-integer.cpp
+++ b/flang/lib/Evaluate/fold-integer.cpp
@@ -523,6 +523,9 @@ Expr<Type<TypeCategory::Integer, KIND>> FoldIntrinsicFunction(
}
return result.value;
}));
+ } else if (name == "not") {
+ return FoldElementalIntrinsic<T, T>(
+ context, std::move(funcRef), &Scalar<T>::NOT);
} else if (name == "precision") {
if (const auto *cx{UnwrapExpr<Expr<SomeReal>>(args[0])}) {
return Expr<T>{std::visit(
@@ -657,7 +660,7 @@ Expr<Type<TypeCategory::Integer, KIND>> FoldIntrinsicFunction(
// TODO:
// cshift, dot_product, eoshift,
// findloc, iall, iany, iparity, ibits, image_status, ishftc,
- // matmul, maxloc, minloc, not, pack, product, reduce,
+ // matmul, maxloc, minloc, pack, product, reduce,
// sign, spread, sum, transfer, transpose, unpack
return Expr<T>{std::move(funcRef)};
}
diff --git a/flang/test/Evaluate/folding01.f90 b/flang/test/Evaluate/folding01.f90
index 29708ce1195f..fddc034165e1 100644
--- a/flang/test/Evaluate/folding01.f90
+++ b/flang/test/Evaluate/folding01.f90
@@ -135,4 +135,8 @@ module m
logical, parameter :: test_max_a1 = all(max(x1a, x2a).EQ.[11, 12, 13, 14])
logical, parameter :: test_min_a1 = all(min(x1a, x2a).EQ.[1, 2, 3, 4])
+ logical, parameter :: test_not_zero = not(0).EQ.-1
+ logical, parameter :: test_not_neg_one = not(-1).EQ.0
+ logical, parameter :: test_not_array = all(not([5, 6, 7]).EQ.[-6, -7, -8])
+
end module