Skip to content

[flang][cuda] Fix lowering when step is a variable #119421

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

Merged
merged 1 commit into from
Dec 10, 2024

Conversation

clementval
Copy link
Contributor

Add missing conversion.

@llvmbot llvmbot added flang Flang issues not falling into any other category flang:fir-hlfir labels Dec 10, 2024
@llvmbot
Copy link
Member

llvmbot commented Dec 10, 2024

@llvm/pr-subscribers-flang-fir-hlfir

Author: Valentin Clement (バレンタイン クレメン) (clementval)

Changes

Add missing conversion.


Full diff: https://github.com/llvm/llvm-project/pull/119421.diff

2 Files Affected:

  • (modified) flang/lib/Lower/Bridge.cpp (+4-2)
  • (modified) flang/test/Lower/CUDA/cuda-kernel-loop-directive.cuf (+15)
diff --git a/flang/lib/Lower/Bridge.cpp b/flang/lib/Lower/Bridge.cpp
index ce8e18bea26db5..de2b941b688bee 100644
--- a/flang/lib/Lower/Bridge.cpp
+++ b/flang/lib/Lower/Bridge.cpp
@@ -3037,8 +3037,10 @@ class FirConverter : public Fortran::lower::AbstractConverter {
           fir::getBase(genExprValue(*Fortran::semantics::GetExpr(bounds->upper),
                                     stmtCtx))));
       if (bounds->step)
-        steps.push_back(fir::getBase(
-            genExprValue(*Fortran::semantics::GetExpr(bounds->step), stmtCtx)));
+        steps.push_back(builder->createConvert(
+            crtLoc, idxTy,
+            fir::getBase(genExprValue(
+                *Fortran::semantics::GetExpr(bounds->step), stmtCtx))));
       else // If `step` is not present, assume it is `1`.
         steps.push_back(builder->createIntegerConstant(loc, idxTy, 1));
 
diff --git a/flang/test/Lower/CUDA/cuda-kernel-loop-directive.cuf b/flang/test/Lower/CUDA/cuda-kernel-loop-directive.cuf
index aac569b6eb35bd..09aefc055e6fa1 100644
--- a/flang/test/Lower/CUDA/cuda-kernel-loop-directive.cuf
+++ b/flang/test/Lower/CUDA/cuda-kernel-loop-directive.cuf
@@ -98,3 +98,18 @@ end subroutine
 
 ! CHECK-LABEL: func.func @_QPsub2
 ! CHECK: cuf.kernel
+
+subroutine sub3()
+  integer, device :: a(10), b(10)
+  integer :: lb = 1
+  integer :: n = 10
+  integer :: s = 1
+
+  !$cuf kernel do <<< *, * >>>
+  do i = lb, n, s
+    a(i) = a(i) * b(i)
+  end do
+end
+
+! CHECK-LABEL: func.func @_QPsub3
+! CHECK: cuf.kernel

@clementval clementval merged commit 0469bb9 into llvm:main Dec 10, 2024
8 of 10 checks passed
@clementval clementval deleted the cuf_kernel_variables branch December 10, 2024 17:48
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
flang:fir-hlfir flang Flang issues not falling into any other category
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants