* The DSE code that tested for overlapping needed to take into account the fact
authorBill Wendling <isanbard@gmail.com>
Wed, 30 Mar 2011 21:37:19 +0000 (21:37 +0000)
committerBill Wendling <isanbard@gmail.com>
Wed, 30 Mar 2011 21:37:19 +0000 (21:37 +0000)
  that one of the numbers is signed while the other is unsigned. This could lead
  to a wrong result when the signed was promoted to an unsigned int.

* Add the data layout line to the testcase so that it will test the appropriate
  thing.

Patch by David Terei!

git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@128577 91177308-0d34-0410-b5e6-96231b3b80d8

lib/Transforms/Scalar/DeadStoreElimination.cpp
test/Transforms/DeadStoreElimination/2011-03-25-DSEMiscompile.ll

index f473cf5ca54a9991e9897104e271f30fa7bf9c22..9f36a3869173ca99920a5dcff80fb1c117ad992c 100644 (file)
@@ -361,8 +361,10 @@ static bool isCompleteOverwrite(const AliasAnalysis::Location &Later,
   //
   //        |--earlier--|
   //    |-----  later  ------|
+  //
+  // We have to be careful here as *Off is signed while *.Size is unsigned.
   if (EarlierOff >= LaterOff &&
-      EarlierOff + Earlier.Size <= LaterOff + Later.Size)
+      uint64_t(EarlierOff - LaterOff) + Earlier.Size <= Later.Size)
     return true;
 
   // Otherwise, they don't completely overlap.
index e268dd54140a690f8cf3adb61303ca71bc737d6b..079eec43bf853b6e28637f3f02cb1a0befc281d3 100644 (file)
@@ -1,5 +1,6 @@
 ; RUN: opt < %s -basicaa -dse -S | FileCheck %s
 ; PR9561
+target datalayout = "e-p:32:32:32-i1:8:8-i8:8:8-i16:16:16-i32:32:32-i64:32:64-f32:32:32-f64:32:64-v64:64:64-v128:128:128-a0:0:64-f80:128:128-n8:16:32"
 target triple = "i386-apple-darwin9.8"
 
 @A = external global [0 x i32]