r218714 - Make better use of zext and sign information revert saga

Geoff Berry via llvm-commits llvm-commits at lists.llvm.org
Thu Aug 27 11:28:33 PDT 2015


Hi All,

I've tracked down a failure in SPEC2006 to BasicAliasAnalysis, and I believe
the fix is part of the code touched by the repeated revert/un-revert cycle
set off by the original change in the subject line above.  Specifically, the
patch that I believe fixes the failure is:

     Value *Result = GetLinearExpression(CastOp, Scale, Offset, Extension,
DL,
                                         Depth + 1, AC, DT);
     Scale = Scale.zext(OldWidth);
-    Offset = Offset.zext(OldWidth);
+
+    // We have to sign-extend even if Extension == EK_ZeroExt as we can't
+    // decompose a sign extension (i.e. zext(x - 1) != zext(x) - zext(-1)).
+    Offset = Offset.sext(OldWidth);

Is this a known issue that someone is working to address, or a case of a bad
series of reverts/un-reverts?  Hal, it looks like you introduced this code
in r221876.  Is this bug fix part of the original patch worth checking in
separately?  Quentin, can you comment on whether just this part of the patch
is okay w.r.t. the failures that caused you to most recently revert it?

Here is a test case that demonstrates the problem.  Without this fix,
basicaa returns NoAlias for the two GEPs, which causes gvn to replace the
load with undef.

; RUN: opt < %s -basicaa -aa-eval -print-all-alias-modref-info
-disable-output 2>&1 | FileCheck %s
target datalayout = "e-m:e-i64:64-i128:128-n32:64-S128"
target triple = "aarch64--linux-gnu"

declare noalias i8* @malloc(i64)

; CHECK-LABEL: gvnbadundef:
; CHECK:  MustAlias: i8* %idx_minus1_sext_ptr, i8* %%idx_sext_minus1_ptr
define i8 @gvnbadundef(i8 %val, i64 %size, i32 %idx) {
entry:
  %mem = tail call noalias i8* @malloc(i64 %size)

  ; mem[idx-1] = val
  %idx_minus1 = add nsw i32 %idx, -1
  %idx_minus1_sext = sext i32 %idx_minus1 to i64
  %idx_minus1_sext_ptr = getelementptr inbounds i8, i8* %mem, i64
%idx_minus1_sext
  store i8 %val, i8* %idx_minus1_sext_ptr, align 1

  ; return mem[idx-1]
  %idx_sext = sext i32 %idx to i64
  %idx_sext_minus1 = add nsw i64 %idx_sext, -1
  %idx_sext_minus1_ptr = getelementptr inbounds i8, i8* %mem, i64
%idx_sext_minus1
  %load4 = load i8, i8* %idx_sext_minus1_ptr, align 1
  ret i8 %load4
}


--
Geoff Berry
Employee of Qualcomm Innovation Center, Inc.
 Qualcomm Innovation Center, Inc. is a member of Code Aurora Forum, a Linux
Foundation Collaborative Project




More information about the llvm-commits mailing list