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

MemCpyOpt: uses sext instead of zext for memcpy/memset size subtraction #47041

Closed
nunoplopes opened this issue Sep 30, 2020 · 1 comment
Closed
Labels
bugzilla Issues migrated from bugzilla miscompilation

Comments

@nunoplopes
Copy link
Member

Bugzilla Link 47697
Version trunk
OS All
CC @ahmedbougacha,@d0k,@fhahn,@aqjune,@RKSimon

Extended Description

Test: Transforms/MemCpyOpt/memset-memcpy-redundant-memset.ll

MemCpyOpt sign-extends the difference between memcpy/memset sizes instead of zero-extending them.

https://alive2.llvm.org/ce/z/RgKeyt


define void @​src(* %dst, * %src, i8 %dst_size, i8 %src_size, i8 %c) {
memset * %dst align 1, i8 %c, i8 %dst_size
memcpy * %dst align 1, * %src align 1, i8 %src_size
ret void
}
=>
define void @​src(* %dst, * %src, i8 %dst_size, i8 %src_size, i8 %c) {
%1 = usub_sat i8 %dst_size, %src_size
%2 = sext i8 %src_size to i64
%3 = gep * %dst, 1 x i64 %2
memset * %3 align 1, i8 %c, i8 %1
memcpy * %dst align 1, * %src align 1, i8 %src_size
ret void
}
Transformation doesn't verify!
ERROR: Source is more defined than target

Example:

  • %dst = pointer(non-local, block_id=1, offset=96)
  • %src = pointer(non-local, block_id=1, offset=9007199254741152)
    i8 %dst_size = #x83 (131, -125)
    i8 %src_size = #x82 (130, -126)
    i8 %c = any

Source:

SOURCE MEMORY STATE

NON-LOCAL BLOCKS:
Block 0 > size: 0 align: 1 alloc type: 0
Block 1 > size: 2305843009213693952 align: 2 alloc type: 0
Block 2 > align: 2 alloc type: 0

Target:
i8 %1 = #x01 (1)
i64 %2 = #xffffffffffffff82 (18446744073709551490, -126)

  • %3 = pointer(non-local, block_id=1, offset=-30)

Summary:
0 correct transformations
1 incorrect transformations
0 Alive2 errors

https://web.ist.utl.pt/nuno.lopes/alive2/index.php?hash=1546033e6d866cfc&test=Transforms%2FMemCpyOpt%2Fmemset-memcpy-redundant-memset.ll

@llvmbot llvmbot transferred this issue from llvm/llvm-bugzilla-archive Dec 10, 2021
@nikic
Copy link
Contributor

nikic commented Jan 4, 2022

Looks like this issue no longer exists (zext is used).

@nikic nikic closed this as completed Jan 4, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bugzilla Issues migrated from bugzilla miscompilation
Projects
None yet
Development

No branches or pull requests

2 participants