LLVM Bugzilla is read-only and represents the historical archive of all LLVM issues filled before November 26, 2021. Use github to submit LLVM bugs

Bug 47697 - MemCpyOpt: uses sext instead of zext for memcpy/memset size subtraction
Summary: MemCpyOpt: uses sext instead of zext for memcpy/memset size subtraction
Status: NEW
Alias: None
Product: libraries
Classification: Unclassified
Component: Scalar Optimizations (show other bugs)
Version: trunk
Hardware: All All
: P normal
Assignee: Unassigned LLVM Bugs
URL:
Keywords: miscompilation
Depends on:
Blocks:
 
Reported: 2020-09-30 11:43 PDT by Nuno Lopes
Modified: 2020-09-30 14:12 PDT (History)
6 users (show)

See Also:
Fixed By Commit(s):


Attachments

Note You need to log in before you can comment on or make changes to this bug.
Description Nuno Lopes 2020-09-30 11:43:39 PDT
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