Skip to content
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

initializes attribute for pointers not supported #1125

Open
regehr opened this issue Dec 1, 2024 · 5 comments
Open

initializes attribute for pointers not supported #1125

regehr opened this issue Dec 1, 2024 · 5 comments
Labels
memory Memory Model

Comments

@regehr
Copy link
Contributor

regehr commented Dec 1, 2024

I'm getting pervasive arm-tv unit test failures because the middle end is inserting the initializes attribute like this:

define void @func_cvt51(ptr %0, ptr initializes((0, 8)) %1) local_unnamed_addr {
arm_tv_entry:
  %a3_114 = load <8 x i16>, ptr %0, align 1
  %2 = getelementptr i8, ptr %0, i64 16
  %a3_215 = load <8 x i16>, ptr %2, align 1
  %3 = shufflevector <8 x i16> %a3_114, <8 x i16> poison, <8 x i32> <i32 0, i32 2, i32 4, i32 6, i32 poison, i32 poison, i32 poison, i32 poison>
  %a4_19 = shufflevector <8 x i16> %3, <8 x i16> %a3_215, <8 x i32> <i32 0, i32 1, i32 2, i32 3, i32 8, i32 10, i32 12, i32 14>
  %a5_2 = trunc <8 x i16> %a4_19 to <8 x i8>
  store <8 x i8> %a5_2, ptr %1, align 1
  ret void
}

if the job here is to parse and ignore this attribute, then I can produce a patch. on the other hand, if we want to obligate the function to actually initialize that byte range, then the necessary changes are probably beyond my understanding of the memory model.

@regehr
Copy link
Contributor Author

regehr commented Dec 1, 2024

I should add that I find the language describing this attribute in LangRef to be vague. do we have to initialize it to something definite, or can we store poison there? or freeze poison? this language might also be troublesome for us? "This attribute only holds for the memory accessed via this pointer parameter. Other arbitrary accesses to the same memory via other pointers are allowed."

ugh.

@nunoplopes
Copy link
Member

nunoplopes commented Dec 2, 2024

I added preliminary support, which can already check if loads are ok or not.
Missing two things:

  • check that all regions are initialized on function exit
  • change the 'isBasedOnArg' mechanism to record the argument number so the check isn't over block ids (that can be shared across args)

@nunoplopes nunoplopes added the memory Memory Model label Dec 2, 2024
@nunoplopes
Copy link
Member

failing test in LLVM test suite (missing support for function calls):

define i16 @p1_write_only_caller() {
  %ptr = alloca i64 2, align 2
  store i16 0, ptr %ptr, align 2
  call void @p1_write_only(nocapture noread noundef dead_on_unwind initializes((0, 2)) ptr %ptr)
  %l = load i16, ptr %ptr, align 2
  ret i16 %l
}
=>
declare void @p1_write_only(nocapture noread noundef dead_on_unwind initializes((0, 2)) ptr)

define i16 @p1_write_only_caller() {
  %ptr = alloca i64 2, align 2
  call void @p1_write_only(nocapture noread noundef dead_on_unwind initializes((0, 2)) ptr %ptr)
  %l = load i16, ptr %ptr, align 2
  ret i16 %l
}

@regehr
Copy link
Contributor Author

regehr commented Dec 4, 2024

excellent-- initializes is working very well for me now, with just a few lingering problems.

I'm running into an issue with this pair (the same problem occurs in regular or assembly mode):

define dso_local void @f(ptr nocapture %0, i32 zeroext %1) {
  %3 = trunc i32 %1 to i8
  %4 = getelementptr inbounds i8, ptr %0, i64 1000000000000
  store i8 %3, ptr %4, align 1
  ret void
}

and tgt:

define void @f(ptr initializes((1000000000000, 1000000000001)) %0, i32 zeroext %1) {
arm_tv_entry:
  %a7_3 = trunc i32 %1 to i8
  %2 = getelementptr i8, ptr %0, i64 1000000000000
  store i8 %a7_3, ptr %2, align 1
  ret void
}

here I'm getting a refinement failure that goes away if I remove the initializes attribute (in assembly mode this one runs for a long time, when I remove the attribute-- I don't know yet if is eventually succeeds or fails)

@nunoplopes
Copy link
Member

Fixed.

Remaining task:

  • Change the 'isBasedOnArg' mechanism to record the argument number so the check isn't over block ids (that can be shared across args)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
memory Memory Model
Projects
None yet
Development

No branches or pull requests

2 participants