[flang-commits] [flang] [flang][cuda] Fix lowering when step is a variable (PR #119421)

via flang-commits flang-commits at lists.llvm.org
Tue Dec 10 09:39:39 PST 2024


llvmbot wrote:


<!--LLVM PR SUMMARY COMMENT-->

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

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

<details>
<summary>Changes</summary>

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
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

``````````

</details>


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


More information about the flang-commits mailing list