Skip to content

Commit 685757e

Browse files
author
z1_cciauto
authored
merge main into amd-staging (llvm#3195)
2 parents b5ecec4 + e1d962c commit 685757e

File tree

46 files changed

+1725
-672
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

46 files changed

+1725
-672
lines changed

clang-tools-extra/docs/clang-tidy/Contributing.rst

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -657,6 +657,29 @@ directory. The path to this directory is available in a lit test with the varia
657657
.. _FileCheck: https://llvm.org/docs/CommandGuide/FileCheck.html
658658
.. _test/clang-tidy/checkers/google/readability-casting.cpp: https://github.com/llvm/llvm-project/blob/main/clang-tools-extra/test/clang-tidy/checkers/google/readability-casting.cpp
659659

660+
661+
Submitting a Pull Request
662+
-------------------------
663+
664+
Before submitting a pull request, contributors are encouraged to run
665+
:program:`clang-tidy` and :program:`clang-format` on their changes to ensure
666+
code quality and catch potential issues. While :program:`clang-tidy` is not
667+
currently enforced in CI, following this practice helps maintain code
668+
consistency and prevent common errors.
669+
670+
Here's useful command to check your staged changes:
671+
672+
.. code-block:: console
673+
674+
$ git diff --staged -U0 | ./clang-tools-extra/clang-tidy/tool/clang-tidy-diff.py \
675+
-j $(nproc) -path build/ -p1 -only-check-in-db
676+
$ git clang-format
677+
678+
Note that some warnings may be false positives or require careful consideration
679+
before fixing. Use your judgment and feel free to discuss in the pull request
680+
if you're unsure about a particular warning.
681+
682+
660683
Out-of-tree check plugins
661684
-------------------------
662685

clang/include/clang/Basic/BuiltinsAMDGPU.def

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -675,6 +675,7 @@ TARGET_BUILTIN(__builtin_amdgcn_s_wait_asynccnt, "vIUs", "n", "gfx1250-insts")
675675
TARGET_BUILTIN(__builtin_amdgcn_s_wait_tensorcnt, "vIUs", "n", "gfx1250-insts")
676676

677677
TARGET_BUILTIN(__builtin_amdgcn_tanhf, "ff", "nc", "tanh-insts")
678+
TARGET_BUILTIN(__builtin_amdgcn_tanhh, "hh", "nc", "tanh-insts")
678679
TARGET_BUILTIN(__builtin_amdgcn_tanh_bf16, "yy", "nc", "bf16-trans-insts")
679680
TARGET_BUILTIN(__builtin_amdgcn_rcp_bf16, "yy", "nc", "bf16-trans-insts")
680681
TARGET_BUILTIN(__builtin_amdgcn_rsq_bf16, "yy", "nc", "bf16-trans-insts")

clang/lib/CodeGen/TargetBuiltins/AMDGPU.cpp

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -516,6 +516,7 @@ Value *CodeGenFunction::EmitAMDGPUBuiltinExpr(unsigned BuiltinID,
516516
return Builder.CreateCall(F, { Src });
517517
}
518518
case AMDGPU::BI__builtin_amdgcn_tanhf:
519+
case AMDGPU::BI__builtin_amdgcn_tanhh:
519520
case AMDGPU::BI__builtin_amdgcn_tanh_bf16:
520521
return emitBuiltinWithOneOverloadedType<1>(*this, E,
521522
Intrinsic::amdgcn_tanh);

clang/lib/Format/TokenAnnotator.cpp

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -2996,14 +2996,18 @@ class AnnotatingParser {
29962996
const FormatToken *PrevToken = Tok.getPreviousNonComment();
29972997
if (!PrevToken)
29982998
return TT_UnaryOperator;
2999-
if (PrevToken->is(TT_TypeName))
2999+
if (PrevToken->isTypeName(LangOpts))
30003000
return TT_PointerOrReference;
30013001
if (PrevToken->isPlacementOperator() && Tok.is(tok::ampamp))
30023002
return TT_BinaryOperator;
30033003

3004-
const FormatToken *NextToken = Tok.getNextNonComment();
3004+
auto *NextToken = Tok.getNextNonComment();
30053005
if (!NextToken)
30063006
return TT_PointerOrReference;
3007+
if (NextToken->is(tok::greater)) {
3008+
NextToken->setFinalizedType(TT_TemplateCloser);
3009+
return TT_PointerOrReference;
3010+
}
30073011

30083012
if (InTemplateArgument && NextToken->is(tok::kw_noexcept))
30093013
return TT_BinaryOperator;
@@ -3112,7 +3116,7 @@ class AnnotatingParser {
31123116

31133117
// It's more likely that & represents operator& than an uninitialized
31143118
// reference.
3115-
if (Tok.is(tok::amp) && PrevToken && PrevToken->Tok.isAnyIdentifier() &&
3119+
if (Tok.is(tok::amp) && PrevToken->Tok.isAnyIdentifier() &&
31163120
IsChainedOperatorAmpOrMember(PrevToken->getPreviousNonComment()) &&
31173121
NextToken && NextToken->Tok.isAnyIdentifier()) {
31183122
if (auto NextNext = NextToken->getNextNonComment();

clang/test/CodeGenOpenCL/builtins-amdgcn-gfx1250.cl

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -61,6 +61,26 @@ void test_tanh_f32(global float* out, float a)
6161
*out = __builtin_amdgcn_tanhf(a);
6262
}
6363

64+
// CHECK-LABEL: @test_tanh_f16(
65+
// CHECK-NEXT: entry:
66+
// CHECK-NEXT: [[OUT_ADDR:%.*]] = alloca ptr addrspace(1), align 8, addrspace(5)
67+
// CHECK-NEXT: [[A_ADDR:%.*]] = alloca ptr addrspace(1), align 8, addrspace(5)
68+
// CHECK-NEXT: [[OUT_ADDR_ASCAST:%.*]] = addrspacecast ptr addrspace(5) [[OUT_ADDR]] to ptr
69+
// CHECK-NEXT: [[A_ADDR_ASCAST:%.*]] = addrspacecast ptr addrspace(5) [[A_ADDR]] to ptr
70+
// CHECK-NEXT: store ptr addrspace(1) [[OUT:%.*]], ptr [[OUT_ADDR_ASCAST]], align 8
71+
// CHECK-NEXT: store ptr addrspace(1) [[A:%.*]], ptr [[A_ADDR_ASCAST]], align 8
72+
// CHECK-NEXT: [[TMP0:%.*]] = load ptr addrspace(1), ptr [[A_ADDR_ASCAST]], align 8
73+
// CHECK-NEXT: [[TMP1:%.*]] = load half, ptr addrspace(1) [[TMP0]], align 2
74+
// CHECK-NEXT: [[TMP2:%.*]] = call half @llvm.amdgcn.tanh.f16(half [[TMP1]])
75+
// CHECK-NEXT: [[TMP3:%.*]] = load ptr addrspace(1), ptr [[OUT_ADDR_ASCAST]], align 8
76+
// CHECK-NEXT: store half [[TMP2]], ptr addrspace(1) [[TMP3]], align 2
77+
// CHECK-NEXT: ret void
78+
//
79+
void test_tanh_f16(global half* out, global half* a)
80+
{
81+
*out = __builtin_amdgcn_tanhh(*a);
82+
}
83+
6484
// CHECK-LABEL: @test_tanh_bf16(
6585
// CHECK-NEXT: entry:
6686
// CHECK-NEXT: [[OUT_ADDR:%.*]] = alloca ptr addrspace(1), align 8, addrspace(5)

clang/unittests/Format/TokenAnnotatorTest.cpp

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -390,6 +390,10 @@ TEST_F(TokenAnnotatorTest, UnderstandsUsesOfStarAndAmp) {
390390
EXPECT_TOKEN(Tokens[20], tok::l_brace, TT_CompoundRequirementLBrace);
391391
EXPECT_TOKEN(Tokens[22], tok::star, TT_BinaryOperator);
392392

393+
Tokens = annotate("bool foo = requires { static_cast<Foo &&>(1); };");
394+
ASSERT_EQ(Tokens.size(), 17u) << Tokens;
395+
EXPECT_TOKEN(Tokens[8], tok::ampamp, TT_PointerOrReference);
396+
393397
Tokens = annotate("return s.operator int *();");
394398
ASSERT_EQ(Tokens.size(), 10u) << Tokens;
395399
// Not TT_FunctionDeclarationName.

flang/lib/Optimizer/CodeGen/CodeGen.cpp

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1123,6 +1123,16 @@ struct AllocMemOpConversion : public fir::FIROpConversion<fir::AllocMemOp> {
11231123
for (mlir::Value opnd : adaptor.getOperands())
11241124
size = rewriter.create<mlir::LLVM::MulOp>(
11251125
loc, ity, size, integerCast(loc, rewriter, ity, opnd));
1126+
1127+
// As the return value of malloc(0) is implementation defined, allocate one
1128+
// byte to ensure the allocation status being true. This behavior aligns to
1129+
// what the runtime has.
1130+
mlir::Value zero = genConstantIndex(loc, ity, rewriter, 0);
1131+
mlir::Value one = genConstantIndex(loc, ity, rewriter, 1);
1132+
mlir::Value cmp = rewriter.create<mlir::LLVM::ICmpOp>(
1133+
loc, mlir::LLVM::ICmpPredicate::sgt, size, zero);
1134+
size = rewriter.create<mlir::LLVM::SelectOp>(loc, cmp, size, one);
1135+
11261136
auto mallocTyWidth = lowerTy().getIndexTypeBitwidth();
11271137
auto mallocTy =
11281138
mlir::IntegerType::get(rewriter.getContext(), mallocTyWidth);

flang/test/Fir/alloc-32.fir

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,9 @@ func.func @allocmem_scalar_nonchar() -> !fir.heap<i32> {
2020
// CHECK-SAME: i32 %[[len:.*]])
2121
// CHECK: %[[mul1:.*]] = sext i32 %[[len]] to i64
2222
// CHECK: %[[mul2:.*]] = mul i64 1, %[[mul1]]
23-
// CHECK: %[[trunc:.*]] = trunc i64 %[[mul2]] to i32
23+
// CHECK: %[[cmp:.*]] = icmp sgt i64 %[[mul2]], 0
24+
// CHECK: %[[sz:.*]] = select i1 %[[cmp]], i64 %[[mul2]], i64 1
25+
// CHECK: %[[trunc:.*]] = trunc i64 %[[sz]] to i32
2426
// CHECK: call ptr @malloc(i32 %[[trunc]])
2527
func.func @allocmem_scalar_dynchar(%l : i32) -> !fir.heap<!fir.char<1,?>> {
2628
%1 = fir.allocmem !fir.char<1,?>(%l : i32)

flang/test/Fir/alloc.fir

Lines changed: 36 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -87,7 +87,9 @@ func.func @alloca_scalar_dynchar_kind(%l : i32) -> !fir.ref<!fir.char<2,?>> {
8787
// CHECK-SAME: i32 %[[len:.*]])
8888
// CHECK: %[[mul1:.*]] = sext i32 %[[len]] to i64
8989
// CHECK: %[[mul2:.*]] = mul i64 1, %[[mul1]]
90-
// CHECK: call ptr @malloc(i64 %[[mul2]])
90+
// CHECK: %[[cmp:.*]] = icmp sgt i64 %[[mul2]], 0
91+
// CHECK: %[[size:.*]] = select i1 %[[cmp]], i64 %[[mul2]], i64 1
92+
// CHECK: call ptr @malloc(i64 %[[size]])
9193
func.func @allocmem_scalar_dynchar(%l : i32) -> !fir.heap<!fir.char<1,?>> {
9294
%1 = fir.allocmem !fir.char<1,?>(%l : i32)
9395
return %1 : !fir.heap<!fir.char<1,?>>
@@ -97,7 +99,9 @@ func.func @allocmem_scalar_dynchar(%l : i32) -> !fir.heap<!fir.char<1,?>> {
9799
// CHECK-SAME: i32 %[[len:.*]])
98100
// CHECK: %[[mul1:.*]] = sext i32 %[[len]] to i64
99101
// CHECK: %[[mul2:.*]] = mul i64 2, %[[mul1]]
100-
// CHECK: call ptr @malloc(i64 %[[mul2]])
102+
// CHECK: %[[cmp:.*]] = icmp sgt i64 %[[mul2]], 0
103+
// CHECK: %[[size:.*]] = select i1 %[[cmp]], i64 %[[mul2]], i64 1
104+
// CHECK: call ptr @malloc(i64 %[[size]])
101105
func.func @allocmem_scalar_dynchar_kind(%l : i32) -> !fir.heap<!fir.char<2,?>>{
102106
%1 = fir.allocmem !fir.char<2,?>(%l : i32)
103107
return %1 : !fir.heap<!fir.char<2,?>>
@@ -152,7 +156,9 @@ func.func @allocmem_array_of_char() -> !fir.heap<!fir.array<3x3x!fir.char<1,10>>
152156
// CHECK-SAME: i32 %[[len:.*]])
153157
// CHECK: %[[mul1:.*]] = sext i32 %[[len]] to i64
154158
// CHECK: %[[mul2:.*]] = mul i64 9, %[[mul1]]
155-
// CHECK: call ptr @malloc(i64 %[[mul2]])
159+
// CHECK: %[[cmp:.*]] = icmp sgt i64 %[[mul2]], 0
160+
// CHECK: %[[size:.*]] = select i1 %[[cmp]], i64 %[[mul2]], i64 1
161+
// CHECK: call ptr @malloc(i64 %[[size]])
156162
func.func @allocmem_array_of_dynchar(%l: i32) -> !fir.heap<!fir.array<3x3x!fir.char<1,?>>> {
157163
%1 = fir.allocmem !fir.array<3x3x!fir.char<1,?>>(%l : i32)
158164
return %1 : !fir.heap<!fir.array<3x3x!fir.char<1,?>>>
@@ -180,7 +186,9 @@ func.func @alloca_dynarray_of_nonchar2(%e: index) -> !fir.ref<!fir.array<?x?xi32
180186
// CHECK-LABEL: define ptr @allocmem_dynarray_of_nonchar(
181187
// CHECK-SAME: i64 %[[extent:.*]])
182188
// CHECK: %[[prod1:.*]] = mul i64 12, %[[extent]]
183-
// CHECK: call ptr @malloc(i64 %[[prod1]])
189+
// CHECK: %[[cmp:.*]] = icmp sgt i64 %[[prod1]], 0
190+
// CHECK: %[[size:.*]] = select i1 %[[cmp]], i64 %[[prod1]], i64 1
191+
// CHECK: call ptr @malloc(i64 %[[size]])
184192
func.func @allocmem_dynarray_of_nonchar(%e: index) -> !fir.heap<!fir.array<3x?xi32>> {
185193
%1 = fir.allocmem !fir.array<3x?xi32>, %e
186194
return %1 : !fir.heap<!fir.array<3x?xi32>>
@@ -190,7 +198,9 @@ func.func @allocmem_dynarray_of_nonchar(%e: index) -> !fir.heap<!fir.array<3x?xi
190198
// CHECK-SAME: i64 %[[extent:.*]])
191199
// CHECK: %[[prod1:.*]] = mul i64 4, %[[extent]]
192200
// CHECK: %[[prod2:.*]] = mul i64 %[[prod1]], %[[extent]]
193-
// CHECK: call ptr @malloc(i64 %[[prod2]])
201+
// CHECK: %[[cmp:.*]] = icmp sgt i64 %[[prod2]], 0
202+
// CHECK: %[[size:.*]] = select i1 %[[cmp]], i64 %[[prod2]], i64 1
203+
// CHECK: call ptr @malloc(i64 %[[size]])
194204
func.func @allocmem_dynarray_of_nonchar2(%e: index) -> !fir.heap<!fir.array<?x?xi32>> {
195205
%1 = fir.allocmem !fir.array<?x?xi32>, %e, %e
196206
return %1 : !fir.heap<!fir.array<?x?xi32>>
@@ -218,7 +228,9 @@ func.func @alloca_dynarray_of_char2(%e : index) -> !fir.ref<!fir.array<?x?x!fir.
218228
// CHECK-LABEL: define ptr @allocmem_dynarray_of_char(
219229
// CHECK-SAME: i64 %[[extent:.*]])
220230
// CHECK: %[[prod1:.*]] = mul i64 60, %[[extent]]
221-
// CHECK: call ptr @malloc(i64 %[[prod1]])
231+
// CHECK: %[[cmp:.*]] = icmp sgt i64 %[[prod1]], 0
232+
// CHECK: %[[size:.*]] = select i1 %[[cmp]], i64 %[[prod1]], i64 1
233+
// CHECK: call ptr @malloc(i64 %[[size]])
222234
func.func @allocmem_dynarray_of_char(%e : index) -> !fir.heap<!fir.array<3x?x!fir.char<2,10>>> {
223235
%1 = fir.allocmem !fir.array<3x?x!fir.char<2,10>>, %e
224236
return %1 : !fir.heap<!fir.array<3x?x!fir.char<2,10>>>
@@ -228,7 +240,9 @@ func.func @allocmem_dynarray_of_char(%e : index) -> !fir.heap<!fir.array<3x?x!fi
228240
// CHECK-SAME: i64 %[[extent:.*]])
229241
// CHECK: %[[prod1:.*]] = mul i64 20, %[[extent]]
230242
// CHECK: %[[prod2:.*]] = mul i64 %[[prod1]], %[[extent]]
231-
// CHECK: call ptr @malloc(i64 %[[prod2]])
243+
// CHECK: %[[cmp:.*]] = icmp sgt i64 %[[prod2]], 0
244+
// CHECK: %[[size:.*]] = select i1 %[[cmp]], i64 %[[mul2]], i64 1
245+
// CHECK: call ptr @malloc(i64 %[[size]])
232246
func.func @allocmem_dynarray_of_char2(%e : index) -> !fir.heap<!fir.array<?x?x!fir.char<2,10>>> {
233247
%1 = fir.allocmem !fir.array<?x?x!fir.char<2,10>>, %e, %e
234248
return %1 : !fir.heap<!fir.array<?x?x!fir.char<2,10>>>
@@ -261,7 +275,9 @@ func.func @alloca_dynarray_of_dynchar2(%l: i32, %e : index) -> !fir.ref<!fir.arr
261275
// CHECK: %[[prod1:.*]] = sext i32 %[[len]] to i64
262276
// CHECK: %[[prod2:.*]] = mul i64 6, %[[prod1]]
263277
// CHECK: %[[prod3:.*]] = mul i64 %[[prod2]], %[[extent]]
264-
// CHECK: call ptr @malloc(i64 %[[prod3]])
278+
// CHECK: %[[cmp:.*]] = icmp sgt i64 %[[prod3]], 0
279+
// CHECK: %[[size:.*]] = select i1 %[[cmp]], i64 %[[prod3]], i64 1
280+
// CHECK: call ptr @malloc(i64 %[[size]])
265281
func.func @allocmem_dynarray_of_dynchar(%l: i32, %e : index) -> !fir.heap<!fir.array<3x?x!fir.char<2,?>>> {
266282
%1 = fir.allocmem !fir.array<3x?x!fir.char<2,?>>(%l : i32), %e
267283
return %1 : !fir.heap<!fir.array<3x?x!fir.char<2,?>>>
@@ -273,7 +289,9 @@ func.func @allocmem_dynarray_of_dynchar(%l: i32, %e : index) -> !fir.heap<!fir.a
273289
// CHECK: %[[prod1:.*]] = mul i64 2, %[[a]]
274290
// CHECK: %[[prod2:.*]] = mul i64 %[[prod1]], %[[extent]]
275291
// CHECK: %[[prod3:.*]] = mul i64 %[[prod2]], %[[extent]]
276-
// CHECK: call ptr @malloc(i64 %[[prod3]])
292+
// CHECK: %[[cmp:.*]] = icmp sgt i64 %[[prod3]], 0
293+
// CHECK: %[[size:.*]] = select i1 %[[cmp]], i64 %[[prod3]], i64 1
294+
// CHECK: call ptr @malloc(i64 %[[size]])
277295
func.func @allocmem_dynarray_of_dynchar2(%l: i32, %e : index) -> !fir.heap<!fir.array<?x?x!fir.char<2,?>>> {
278296
%1 = fir.allocmem !fir.array<?x?x!fir.char<2,?>>(%l : i32), %e, %e
279297
return %1 : !fir.heap<!fir.array<?x?x!fir.char<2,?>>>
@@ -312,7 +330,9 @@ func.func @alloca_array_with_holes_dynchar(%arg0: index, %arg1: index) -> !fir.r
312330
// CHECK-SAME: i64 %[[e1:.*]], i64 %[[e2:.*]])
313331
// CHECK: %[[a:.*]] = mul i64 240, %[[e1]]
314332
// CHECK: %[[b:.*]] = mul i64 %3, %[[e2]]
315-
// CHECK: call ptr @malloc(i64 %[[b]])
333+
// CHECK: %[[cmp:.*]] = icmp sgt i64 %[[b]], 0
334+
// CHECK: %[[size:.*]] = select i1 %[[cmp]], i64 %[[b]], i64 1
335+
// CHECK: call ptr @malloc(i64 %[[size]])
316336
func.func @allocmem_array_with_holes_nonchar(%0 : index, %1 : index) -> !fir.heap<!fir.array<4x?x3x?x5xi32>> {
317337
%a = fir.allocmem !fir.array<4x?x3x?x5xi32>, %0, %1
318338
return %a : !fir.heap<!fir.array<4x?x3x?x5xi32>>
@@ -321,7 +341,9 @@ func.func @allocmem_array_with_holes_nonchar(%0 : index, %1 : index) -> !fir.hea
321341
// CHECK-LABEL: define ptr @allocmem_array_with_holes_char(
322342
// CHECK-SAME: i64 %[[e:.*]])
323343
// CHECK: %[[mul:.*]] = mul i64 240, %[[e]]
324-
// CHECK: call ptr @malloc(i64 %[[mul]])
344+
// CHECK: %[[cmp:.*]] = icmp sgt i64 %[[mul]], 0
345+
// CHECK: %[[size:.*]] = select i1 %[[cmp]], i64 %[[mul]], i64 1
346+
// CHECK: call ptr @malloc(i64 %[[size]])
325347
func.func @allocmem_array_with_holes_char(%e: index) -> !fir.heap<!fir.array<3x?x4x!fir.char<2,10>>> {
326348
%1 = fir.allocmem !fir.array<3x?x4x!fir.char<2,10>>, %e
327349
return %1 : !fir.heap<!fir.array<3x?x4x!fir.char<2,10>>>
@@ -331,7 +353,9 @@ func.func @allocmem_array_with_holes_char(%e: index) -> !fir.heap<!fir.array<3x?
331353
// CHECK-SAME: i64 %[[len:.*]], i64 %[[extent:.*]])
332354
// CHECK: %[[a:.*]] = mul i64 24, %[[len]]
333355
// CHECK: %[[b:.*]] = mul i64 %[[a]], %[[extent]]
334-
// CHECK: call ptr @malloc(i64 %[[b]])
356+
// CHECK: %[[cmp:.*]] = icmp sgt i64 %[[b]], 0
357+
// CHECK: %[[size:.*]] = select i1 %[[cmp]], i64 %[[b]], i64 1
358+
// CHECK: call ptr @malloc(i64 %[[size]])
335359
func.func @allocmem_array_with_holes_dynchar(%arg0: index, %arg1: index) -> !fir.heap<!fir.array<3x?x4x!fir.char<2,?>>> {
336360
%1 = fir.allocmem !fir.array<3x?x4x!fir.char<2,?>>(%arg0 : index), %arg1
337361
return %1 : !fir.heap<!fir.array<3x?x4x!fir.char<2,?>>>

flang/test/Fir/arrexp.fir

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -146,7 +146,9 @@ func.func @f6(%arg0: !fir.box<!fir.array<?xf32>>, %arg1: f32) {
146146
// CHECK: %[[EXT_GEP:.*]] = getelementptr {{.*}} %[[A]], i32 0, i32 7, i64 0, i32 1
147147
// CHECK: %[[EXTENT:.*]] = load i64, ptr %[[EXT_GEP]]
148148
// CHECK: %[[SIZE:.*]] = mul i64 4, %[[EXTENT]]
149-
// CHECK: %[[MALLOC:.*]] = call ptr @malloc(i64 %[[SIZE]])
149+
// CHECK: %[[CMP:.*]] = icmp sgt i64 %[[SIZE]], 0
150+
// CHECK: %[[SZ:.*]] = select i1 %[[CMP]], i64 %[[SIZE]], i64 1
151+
// CHECK: %[[MALLOC:.*]] = call ptr @malloc(i64 %[[SZ]])
150152
%1 = fir.slice %c2, %c10, %c1 : (index, index, index) -> !fir.slice<1>
151153
%2 = fir.array_load %arg0 [%1] : (!fir.box<!fir.array<?xf32>>, !fir.slice<1>) -> !fir.array<?xf32>
152154
%3 = fir.slice %c1, %c9, %c1 : (index, index, index) -> !fir.slice<1>

0 commit comments

Comments
 (0)