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

            Bug ID: 45470
           Summary: GVN incorrectly optimizes away a non-local load
           Product: libraries
           Version: trunk
          Hardware: All
                OS: Linux
            Status: NEW
          Severity: normal
          Priority: P
         Component: Scalar Optimizations
          Assignee: unassignedb...@nondot.org
          Reporter: changpeng.f...@amd.com
                CC: llvm-bugs@lists.llvm.org

Created attachment 23321
  --> https://bugs.llvm.org/attachment.cgi?id=23321&action=edit
opt -O1 -gcn bug.ll

GVN pass incorrectly optimized away the load. Actually the load should have a
dependence on the store inside the loop. but it looks like the memory
dependence is somehow skipped and the load is found to depend on the alloca,
and thus replaced with undef.

---------------------------
.preheader:                                       ; preds = %.preheader, %bb
  %phi.i = phi i32 [ %next.i, %.preheader ], [ undef, %bb ]
  %tmp1 = shl nuw nsw i32 %phi.i, 2
  %offset = or i32 %tmp1, 2
  %store.addr = getelementptr inbounds [16 x i16], [16 x i16] addrspace(5)*
%alloca, i32 0, i32 %offset
  store i16 11878, i16 addrspace(5)* %store.addr, align 2
  %next.i = add nuw nsw i32 %phi.i, 1
  %cmp = icmp ult i32 %next.i, 8
  br i1 %cmp, label %.preheader, label %.loopexit

.loopexit:                                        ; preds = %.preheader
  %addr = bitcast [16 x i16] addrspace(5)* %alloca to half addrspace(5)*
  %result = load half, half addrspace(5)* %addr, align 2
  call void @chfang(half %result)
  unreachable
--------------------

to reproduce:
  opt -O1 -gvn -S bug.ll
------------------------
You will find:
.loopexit:                                        ; preds = %.preheader
  %addr = bitcast [16 x i16] addrspace(5)* %alloca to half addrspace(5)*
  tail call void @chfang(half undef)
  unreachable

We don't think this non-local load should be optimized away.

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

Reply via email to