[flang-commits] [flang] 6243b90 - [flang] Do not create arith.extui with same from/to type
Valentin Clement via flang-commits
flang-commits at lists.llvm.org
Sun Apr 24 11:37:55 PDT 2022
Author: Valentin Clement (バレンタイン クレメン)
Date: 2022-04-24T20:37:48+02:00
New Revision: 6243b90ead7a4d9e4097849498bea6749836de98
URL: https://github.com/llvm/llvm-project/commit/6243b90ead7a4d9e4097849498bea6749836de98
DIFF: https://github.com/llvm/llvm-project/commit/6243b90ead7a4d9e4097849498bea6749836de98.diff
LOG: [flang] Do not create arith.extui with same from/to type
In some case the lowering of `ichar` is generating an `arith.extui` operation
with the same from/to type. This operation do not accept from/to types to be
the same. If the from/to types are identical, we do not generate the extra
operation.
Reviewed By: jeanPerier
Differential Revision: https://reviews.llvm.org/D124107
Added:
Modified:
flang/lib/Lower/IntrinsicCall.cpp
flang/test/Lower/Intrinsics/ichar.f90
Removed:
################################################################################
diff --git a/flang/lib/Lower/IntrinsicCall.cpp b/flang/lib/Lower/IntrinsicCall.cpp
index cf68b141bd24e..957a759721478 100644
--- a/flang/lib/Lower/IntrinsicCall.cpp
+++ b/flang/lib/Lower/IntrinsicCall.cpp
@@ -2614,6 +2614,8 @@ IntrinsicLibrary::genIchar(mlir::Type resultType,
}
LLVM_DEBUG(llvm::dbgs() << "ichar(" << charVal << ")\n");
auto code = helper.extractCodeFromSingleton(charVal);
+ if (code.getType() == resultType)
+ return code;
return builder.create<mlir::arith::ExtUIOp>(loc, resultType, code);
}
diff --git a/flang/test/Lower/Intrinsics/ichar.f90 b/flang/test/Lower/Intrinsics/ichar.f90
index 2597d47f9a8e2..e99fae0f5b193 100644
--- a/flang/test/Lower/Intrinsics/ichar.f90
+++ b/flang/test/Lower/Intrinsics/ichar.f90
@@ -31,3 +31,13 @@ subroutine ichar_test(c)
! CHECK-NEXT: fir.call @{{.*}}EndIoStatement
print *, iachar('X')
end subroutine
+
+! Check that 'arith.extui' op is not generated if type are matching.
+ ! CHECK-LABEL: no_extui
+subroutine no_extui(ch)
+ integer, parameter :: kind = selected_char_kind('ISO_10646')
+ character(*, kind), intent(in) :: ch(:)
+ integer :: i, j
+ ! CHECK-NOT: arith.extui
+ j = ichar(ch(i)(i:i))
+end subroutine
More information about the flang-commits
mailing list