Skip to content

[NewGVN] Miscompile with equal instructions modulo attributes #53218

@nunoplopes

Description

@nunoplopes

NewGVN miscompiles the following function:

@glb = external global i64, align 8

define i64 @src(i64 %tmp) {
  %conv3 = shl nuw i64 %tmp, 32
  store i64 %conv3, i64* @glb, align 8
  %sext = shl i64 %tmp, 32
  %r = lshr exact i64 %sext, 32
  ret i64 %r
}

define i64 @tgt(i64 %tmp) {
  %conv3 = shl i64 %tmp, 32
  store i64 %conv3, i64* @glb, align 8
  ret i64 %tmp
}

NewGVN hashes instructions ignoring attributes like 'nuw', so it assumes that conv3 and sext above are equivalent. But then it uses %conv3 as the leader, and then it calls InstSimplify with shl nuw & lshr extract and bug!

Test case from @regehr.
cc @alinas

Metadata

Metadata

Assignees

No one assigned

    Type

    No type
    No fields configured for issues without a type.

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions