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

[NewGVN] Miscompilation when creating phi-of-ops #53277

Closed
alinas opened this issue Jan 18, 2022 · 3 comments
Closed

[NewGVN] Miscompilation when creating phi-of-ops #53277

alinas opened this issue Jan 18, 2022 · 3 comments

Comments

@alinas
Copy link
Contributor

alinas commented Jan 18, 2022

NewGVN miscompiles the following testcase:

target datalayout = "e-m:e-p270:32:32-p271:32:32-p272:64:64-i64:64-f80:128-n8:16:32:64-S128"
target triple = "x86_64-grtev4-linux-gnu"

%struct.spam.10 = type { i8*, i64 }

define void @zot(%struct.spam.10* %arg1, %struct.spam.10* %arg2) align 32 {
bb56:
  %tmp5 = getelementptr inbounds %struct.spam.10, %struct.spam.10* %arg1, i64 0, i32 0
  %tmp6 = getelementptr inbounds %struct.spam.10, %struct.spam.10* %arg2, i64 0, i32 0
  br label %bb57

bb57:
  %tmp59 = phi i1 [ false, %bb229 ], [ true, %bb56 ]
  %tmp60 = load i8*, i8** %tmp5, align 8
  %tmp61 = load i8, i8* %tmp60, align 1
  %tmp62 = icmp ne i8 %tmp61, 93
  %tmp63 = or i1 %tmp59, %tmp62
  br i1 %tmp63, label %bb229, label %bb237

bb229:
  ; load from tmp5 or tmp6
  %tmp186 = load i8*, i8** %tmp6, align 8
  %tmp209 = getelementptr inbounds i8, i8* %tmp186, i64 2
  store i8* %tmp209, i8** %tmp5, align 8
  br label %bb57

bb237:
  ret void
}

The phiofops it creates uses a value that is modified inside the loop and needs to be reloaded.
(https://alive2.llvm.org/ce/z/gAPk9q)

cc @nunoplopes @fhahn

@nunoplopes
Copy link
Member

nunoplopes commented Jan 23, 2022

Another version without the double pointer indirection:

define void @src(i8* %p, i8* %q) {
bb56:
  br label %bb57

bb57:
  %tmp59 = phi i1 [ false, %bb229 ], [ true, %bb56 ]
  %idx = phi i8 [0, %bb56], [%inc, %bb229]
  %tmp60 = load i8, i8* %p
  %tmp62 = icmp ne i8 %tmp60, 2
  %tmp63 = or i1 %tmp59, %tmp62
  br i1 %tmp63, label %bb229, label %bb237

bb229:
  %inc = add i8 %idx, 1
  store i8 %inc, i8* %q
  br label %bb57

bb237:
  ret void
}

And another one;

define void @src(i8* %p) {
bb56:
  br label %bb57

bb57:
  %tmp59 = phi i1 [ false, %bb229 ], [ true, %bb56 ]
  %tmp60 = load i8, i8* %p
  %tmp62 = icmp ne i8 %tmp60, 2
  %tmp63 = or i1 %tmp59, %tmp62
  br i1 %tmp63, label %bb229, label %bb237

bb229:
  call void @f()
  br label %bb57

bb237:
  ret void
}

@nunoplopes
Copy link
Member

@nunoplopes
Copy link
Member

fixed: 24a49e9

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

No branches or pull requests

3 participants