https://bugs.llvm.org/show_bug.cgi?id=45384

            Bug ID: 45384
           Summary: [CorrelatedValuePropagation / LazyValueInfo]  wrong
                    code generation
           Product: libraries
           Version: 10.0
          Hardware: PC
                OS: Linux
            Status: NEW
          Severity: release blocker
          Priority: P
         Component: Scalar Optimizations
          Assignee: [email protected]
          Reporter: [email protected]
                CC: [email protected]

Created attachment 23301
  --> https://bugs.llvm.org/attachment.cgi?id=23301&action=edit
reduced testcase

Originates from
https://bugs.launchpad.net/ubuntu/+source/postgresql-12/+bug/1867173, where
Ubuntu is building (bootstrapped) clang-10 and runs into a seg fault with
llvm-lto.

I believe I have found a bug in clang-10 which seems to likely be involved in
this problem. This is a reduced test case, which involves an i8 PHI with an
undef entry operand, which is and:ed with 127, clearing the sign bit:

define i32 @fun() {
entry:
  br label %bb1

bb1:
  %P = phi i8 [ undef, %entry ], [ %Or, %bb1 ]
  %Ld = load i8, i8* inttoptr (i64 8 to i8*), align 8
  %And1 = and i8 %Ld, -128
  %And2 = and i8 %P, 127
  %Or = or i8 %And2, %And1
  %C = icmp sgt i8 %Or, -1
  br i1 %C, label %bb1, label %exit

exit:
  %res = zext i1 %C to i32
  ret i32 %res
}

All the bits of %And2 are undef except the sign bit which is used by the icmp.
CorrelatedValuePropagation incorrectly replaces %And2 with %P which makes the
sign bit undefined.

This is observable at llvmorg-10.0.0-rc5 (3562703 / March 19), without the
bootstrap. The problem however (at least with my reduced test case) goes away
with 4878aa3 (March 14). That commit seems to be related exactly to undef
constants in this context. I don't know if that eliminates this bug, or if it
just gets hidden.

./bin/opt -S -mtriple=s390x-linux-gnu -mcpu=z10 ./tc_corrprop.ll
--correlated-propagation -o -   
; ModuleID = './tc_corrprop.ll'
source_filename = "./tc_corrprop.ll"
target triple = "s390x-unknown-linux-gnu"

define i32 @fun() #0 {
entry:
  br label %bb1

bb1:                                              ; preds = %bb1, %entry
  %P = phi i8 [ undef, %entry ], [ %Or, %bb1 ]
  %Ld = load i8, i8* inttoptr (i64 8 to i8*), align 8
  %And1 = and i8 %Ld, -128
  %Or = or i8 %P, %And1
  %C = icmp sgt i8 %Or, -1
  br i1 %C, label %bb1, label %exit

exit:                                             ; preds = %bb1
  %res = zext i1 %C to i32
  ret i32 0
}

attributes #0 = { "target-cpu"="z10" }

-- 
You are receiving this mail because:
You are on the CC list for the bug.
_______________________________________________
llvm-bugs mailing list
[email protected]
https://lists.llvm.org/cgi-bin/mailman/listinfo/llvm-bugs

Reply via email to