[llvm-bugs] [Bug 50208] New: instCombine: incorrect fold of pointer comparison between globals

via llvm-bugs llvm-bugs at lists.llvm.org
Mon May 3 10:41:55 PDT 2021


https://bugs.llvm.org/show_bug.cgi?id=50208

            Bug ID: 50208
           Summary: instCombine: incorrect fold of pointer comparison
                    between globals
           Product: libraries
           Version: trunk
          Hardware: All
                OS: All
            Status: NEW
          Keywords: miscompilation
          Severity: normal
          Priority: P
         Component: Scalar Optimizations
          Assignee: unassignedbugs at nondot.org
          Reporter: nunoplopes at sapo.pt
                CC: juneyoung.lee at sf.snu.ac.kr, llvm-bugs at lists.llvm.org,
                    nikita.ppv at gmail.com, spatel+llvm at rotateright.com

test: Transforms/InstSimplify/ConstProp/icmp-null.ll
The transformation below is only correct if the gep is over i8*, and not with
non-byte-sized types. This is correct: https://alive2.llvm.org/ce/z/S_TsHW

----------------------------------------
@g2 = global 4 bytes, align 4
@g = global 8 bytes, align 4

define i1 @null_gep_ne_global() {
  %__constexpr_0 = ptrtoint * @g2 to i64
  %gep = gep * null, 8 x i64 %__constexpr_0  ; <-- notice the 8 x
  %cmp = icmp ne * %gep, @g
  ret i1 %cmp
}
=>
@g2 = global 4 bytes, align 4
@g = global 8 bytes, align 4

define i1 @null_gep_ne_global() {
  ret i1 1
}
Transformation doesn't verify!

ERROR: Value mismatch

Example:

Source:
i64 %__constexpr_0 = #x924925b6db6f5564 (10540997870133138788,
-7905746203576412828)
* %gep = pointer(non-local, block_id=0, offset=-7905737407482647776)
i1 %cmp = #x0 (0)

SOURCE MEMORY STATE
===================
NON-LOCAL BLOCKS:
Block 0 >       size: 0 align: 1        alloc type: 0   address: 0
Block 1 >       size: 4 align: 4        alloc type: 0   address:
10540997870133138788
Block 2 >       size: 8 align: 4        alloc type: 0   address:
10541006666226903840

Target:
Source value: #x0 (0)
Target value: #x1 (1)

-- 
You are receiving this mail because:
You are on the CC list for the bug.
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.llvm.org/pipermail/llvm-bugs/attachments/20210503/12326290/attachment.html>


More information about the llvm-bugs mailing list