[llvm-bugs] [Bug 51476] New: [AArch64] Peephole pass incorrectly removes comparison

via llvm-bugs llvm-bugs at lists.llvm.org
Sat Aug 14 02:43:40 PDT 2021


            Bug ID: 51476
           Summary: [AArch64] Peephole pass incorrectly removes comparison
           Product: libraries
           Version: trunk
          Hardware: PC
                OS: Linux
            Status: NEW
          Severity: enhancement
          Priority: P
         Component: Backend: AArch64
          Assignee: unassignedbugs at nondot.org
          Reporter: nikita.ppv at gmail.com
                CC: arnaud.degrandmaison at arm.com,
                    llvm-bugs at lists.llvm.org, smithp352 at googlemail.com,
                    Ties.Stuij at arm.com
            Blocks: 51236

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

  call void @unknown(i8 %zext2)
  ret void

  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

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.

Referenced Bugs:

[Bug 51236] [meta] 13.0.0 Release Blockers
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/20210814/f3e59c59/attachment.html>

More information about the llvm-bugs mailing list