Skip to content

InstSimplify: incorrect fold of pointer comparison between globals #49552

Description

@nunoplopes
Bugzilla Link 50208
Version trunk
OS All
CC @aqjune,@RKSimon,@nikic,@rotateright

Extended Description

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)

Activity

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions