diff options
author | Derek Schuff <dschuff@chromium.org> | 2013-02-15 16:12:59 -0800 |
---|---|---|
committer | Derek Schuff <dschuff@chromium.org> | 2013-02-15 16:12:59 -0800 |
commit | 50c20006ea707be7e439c3093d4a064ccfe78b7a (patch) | |
tree | b482850ca0a94a809d7396b4206b7e7a242993e7 | |
parent | de82c04bfc33b44fc650cf7f330dbf26992faf8b (diff) |
Don't fold negative constants into addresss displacements for memory references
This results in trying to reference a negative offset from r15.
R=sehr@chromium.org,jvoung@chromium.org,eliben@chromium.org
BUG= https://code.google.com/p/nativeclient/issues/detail?id=3302
Review URL: https://codereview.chromium.org/12277018
-rw-r--r-- | lib/Target/X86/X86ISelDAGToDAG.cpp | 8 | ||||
-rw-r--r-- | test/NaCl/X86/nacl64-addrmodes.ll | 14 |
2 files changed, 22 insertions, 0 deletions
diff --git a/lib/Target/X86/X86ISelDAGToDAG.cpp b/lib/Target/X86/X86ISelDAGToDAG.cpp index 70cfa7d516..f4a9ca38d2 100644 --- a/lib/Target/X86/X86ISelDAGToDAG.cpp +++ b/lib/Target/X86/X86ISelDAGToDAG.cpp @@ -607,6 +607,14 @@ bool X86DAGToDAGISel::FoldOffsetIntoAddress(uint64_t Offset, if (AM.BaseType == X86ISelAddressMode::FrameIndexBase && !isDispSafeForFrameIndex(Val)) return true; + // LOCALMOD-BEGIN + // Do not allow negative displacements to be folded into memory operations. + // This results in trying to dereference a negative offset from RZP + else if (Subtarget->isTargetNaCl64() && + AM.BaseType == X86ISelAddressMode::RegBase && Val < 0 && + selectingMemOp) + return true; + // LOCALMOD-END } AM.Disp = Val; return false; diff --git a/test/NaCl/X86/nacl64-addrmodes.ll b/test/NaCl/X86/nacl64-addrmodes.ll new file mode 100644 index 0000000000..772424b154 --- /dev/null +++ b/test/NaCl/X86/nacl64-addrmodes.ll @@ -0,0 +1,14 @@ +; RUN: llc -mtriple=x86_64-unknown-nacl -filetype=asm %s -o - \ +; RUN: | FileCheck %s + +; Check that we don't try to fold a negative displacement into a memory +; reference +define i16 @negativedisp(i32 %b) { +; CHECK: negativedisp + %a = alloca [1 x i16], align 2 + %add = add nsw i32 1073741824, %b + %arrayidx = getelementptr inbounds [1 x i16]* %a, i32 0, i32 %add +; CHECK-NOT: nacl:-2147483648( + %c = load i16* %arrayidx, align 2 + ret i16 %c +} |