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

[AArch64] Peephole pass incorrectly removes comparison #50818

Closed
nikic opened this issue Aug 14, 2021 · 4 comments
Closed

[AArch64] Peephole pass incorrectly removes comparison #50818

nikic opened this issue Aug 14, 2021 · 4 comments
Labels
backend:AArch64 bugzilla Issues migrated from bugzilla

Comments

@nikic
Copy link
Contributor

nikic commented Aug 14, 2021

Bugzilla Link 51476
Resolution FIXED
Resolved on Oct 11, 2021 20:29
Version trunk
OS Linux
Blocks #51489
CC @Arnaud-de-Grandmaison-ARM,@DMG862,@smithp35
Fixed by commit(s) 81b1065 b643ee1

Extended Description

target datalayout = "e-m:e-i8:8:32-i16:16:32-i64:64-i128:128-n32:64-S128"
target triple = "aarch64-unknown-linux-gnu"

define void @​test(i8 %arg) {
%tmp = alloca i8
%cmp1 = icmp ne i8 %arg, 1
%zext = zext i1 %cmp1 to i8
store i8 %zext, i8* %tmp
%zext2 = load i8, i8* %tmp
%cmp2 = icmp eq i8 %zext2, 3
br i1 %cmp2, label %exit, label %do_call

do_call:
call void @​unknown(i8 %zext2)
ret void

exit:
ret void
}

declare void @​unknown(i8)

Running through llc produces:

// %bb.0:
str x30, [sp, #-16]! // 8-byte Folded Spill
.cfi_def_cfa_offset 16
.cfi_offset w30, -16
and w8, w0, #​0xff
cmp w8, #​1
cset w0, ne
strb w0, [sp, #​12]
b.ne .LBB0_2
// %bb.1: // %do_call
bl unknown
.LBB0_2: // %common.ret
ldr x30, [sp], #​16 // 8-byte Folded Reload
ret

Note how the final comparison to #​3 has now reuses the result of the comparison to #​1.

This is caused by the new optimization introduced in https://reviews.llvm.org/D98564. From a cursory reading, this optimization was written under the assumption that CmpValue==1 means that the comparison is against #​1, while analyzeCompare() canonicalizes the comparison such that CmpValue==1 indicates a comparison against any non-zero value.

@nikic
Copy link
Contributor Author

nikic commented Aug 14, 2021

Candidate patch: https://reviews.llvm.org/D108076

@nikic
Copy link
Contributor Author

nikic commented Aug 15, 2021

Fixed by 81b1065. Keeping this open to track release/13.x backport.

@tstellar
Copy link
Collaborator

Merged: b643ee1

@tstellar
Copy link
Collaborator

mentioned in issue #51489

@llvmbot llvmbot transferred this issue from llvm/llvm-bugzilla-archive Dec 11, 2021
This issue was closed.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
backend:AArch64 bugzilla Issues migrated from bugzilla
Projects
None yet
Development

No branches or pull requests

2 participants