This is an archive of the discontinued LLVM Phabricator instance.

[Clang][CodeGen] Set the size of llvm.lifetime to unknown for scalable types.
ClosedPublic

Authored by HsiangKai on May 19 2021, 7:37 PM.

Details

Summary

If the memory object is scalable type, we do not know the exact size of
it at compile time. Set the size of lifetime marker to unknown if the
object is scalable one.

Diff Detail

Event Timeline

HsiangKai created this revision.May 19 2021, 7:37 PM
HsiangKai requested review of this revision.May 19 2021, 7:37 PM
Herald added a project: Restricted Project. · View Herald TranscriptMay 19 2021, 7:37 PM

Am I mistaken, or does this test already pass without these changes?

Am I mistaken, or does this test already pass without these changes?

You are right. I didn't confirm it. I need to update the test case. Thanks.

HsiangKai updated this revision to Diff 346656.May 20 2021, 1:31 AM

Update the test case.

craig.topper added inline comments.Jun 2 2021, 1:47 PM
clang/test/CodeGen/RISCV/riscv-v-lifetime.cpp
3 ↗(On Diff #346656)

Probably best to add -disable-llvm-passes so we don't run the optimizer.

8 ↗(On Diff #346656)

Are the templates needed? This was enough to fail for me

vint32m1_t Baz();                                                                                                                                                                                                               
                                                                                                                                                                                                                                
vint32m1_t Test() {                                                                                                                                                                                                             
  const vint32m1_t &a = Baz();                                                                                                                                                                                                  
  return a;                                                                                                                                                                                                                     
}

Or do the templates test additional code paths?

sdesmalen added inline comments.Jun 3 2021, 12:36 AM
clang/lib/CodeGen/CGDecl.cpp
1327

Instead of updating Size here, can you change line 1332 to be:

llvm::Value *SizeV = llvm::ConstantInt::get(Int64Ty, Size.isScalable() ? -1 : Size.getFixedValue())
1332

Does ConstantInt take TypeSize Size as argument?

1558

nit: Given you have to update this line, maybe also to capitalize size -> Size?

Matt added a subscriber: Matt.Jun 3 2021, 8:23 AM
HsiangKai updated this revision to Diff 349750.Jun 3 2021, 7:34 PM

Address comments.

HsiangKai updated this revision to Diff 349751.Jun 3 2021, 7:35 PM

clang format.

HsiangKai marked 5 inline comments as done.Jun 3 2021, 7:37 PM
sdesmalen added inline comments.Jun 4 2021, 1:27 AM
clang/test/CodeGen/RISCV/riscv-v-lifetime.cpp
17 ↗(On Diff #349751)

nit: I'm not sure if there is any policy on this, but for this test you can just as well have 6 CHECK lines, instead of auto-generating all of them, which makes the test a bit easier to read.

// CHECK-LABEL: @_Z4Testv
// CHECK-NEXT:    [[ALLOCA:%.*]] = alloca <vscale x 2 x i32>, align 4
// CHECK-NEXT:    [[BC1:%.*]] = bitcast <vscale x 2 x i32>* [[ALLOCA]] to i8*
// CHECK-NEXT:    call void @llvm.lifetime.start.p0i8(i64 -1, i8* [[BC1]])
// CHECK-NEXT:    [[BC2:%.*]] = bitcast <vscale x 2 x i32>* [[ALLOCA]] to i8*
// CHECK-NEXT:    call void @llvm.lifetime.end.p0i8(i64 -1, i8* [[BC2]])
3 ↗(On Diff #346656)

nit: Does -O1 still have any effect if -disable-llvm-passes is also set?

craig.topper added inline comments.Jun 4 2021, 9:29 AM
clang/test/CodeGen/RISCV/riscv-v-lifetime.cpp
3 ↗(On Diff #346656)

Lifetime markers aren't emitted with -O0.

HsiangKai updated this revision to Diff 350035.Jun 5 2021, 12:31 AM

Simplify the test case.

sdesmalen accepted this revision.Jun 7 2021, 3:37 AM

LGTM, thanks @HsiangKai

clang/test/CodeGen/RISCV/riscv-v-lifetime.cpp
3 ↗(On Diff #346656)

I didn't know that, thanks!

This revision is now accepted and ready to land.Jun 7 2021, 3:37 AM