From 7a9adc7562c103cc9f501bfc017b5c3b92ef0a06 Mon Sep 17 00:00:00 2001 From: Petar Jovanovic Date: Tue, 1 Mar 2016 16:50:08 +0000 Subject: [PATCH] Revert "calculate builtin_object_size if argument is a removable pointer" Revert r262337 as "check-llvm ubsan" step failed on sanitizer-x86_64-linux-fast buildbot. git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@262349 91177308-0d34-0410-b5e6-96231b3b80d8 --- .../InstCombine/InstructionCombining.cpp | 25 ++++------------ .../InstCombine/builtin-object-size-ptr.ll | 34 ---------------------- 2 files changed, 6 insertions(+), 53 deletions(-) delete mode 100644 test/Transforms/InstCombine/builtin-object-size-ptr.ll diff --git a/lib/Transforms/InstCombine/InstructionCombining.cpp b/lib/Transforms/InstCombine/InstructionCombining.cpp index de4dfb5caeb..1b95e9334c1 100644 --- a/lib/Transforms/InstCombine/InstructionCombining.cpp +++ b/lib/Transforms/InstCombine/InstructionCombining.cpp @@ -1942,25 +1942,6 @@ Instruction *InstCombiner::visitAllocSite(Instruction &MI) { SmallVector Users; if (isAllocSiteRemovable(&MI, Users, TLI)) { for (unsigned i = 0, e = Users.size(); i != e; ++i) { - // Lowering all @llvm.objectsize calls first because they may - // use a bitcast/GEP of the alloca we are removing. - Instruction *I = cast_or_null(&*Users[i]); - if (!I) continue; - - if (IntrinsicInst *II = dyn_cast(I)) { - if (II->getIntrinsicID() == Intrinsic::objectsize) { - uint64_t Size; - if (!getObjectSize(II->getArgOperand(0), Size, DL, TLI)) { - ConstantInt *CI = cast(II->getArgOperand(1)); - Size = CI->isZero() ? -1ULL : 0; - } - replaceInstUsesWith(*I, ConstantInt::get(I->getType(), Size)); - eraseInstFromFunction(*I); - Users[i] = nullptr; // Skip examining in the next loop. - } - } - } - for (unsigned i = 0, e = Users.size(); i != e; ++i) { Instruction *I = cast_or_null(&*Users[i]); if (!I) continue; @@ -1970,6 +1951,12 @@ Instruction *InstCombiner::visitAllocSite(Instruction &MI) { C->isFalseWhenEqual())); } else if (isa(I) || isa(I)) { replaceInstUsesWith(*I, UndefValue::get(I->getType())); + } else if (IntrinsicInst *II = dyn_cast(I)) { + if (II->getIntrinsicID() == Intrinsic::objectsize) { + ConstantInt *CI = cast(II->getArgOperand(1)); + uint64_t DontKnow = CI->isZero() ? -1ULL : 0; + replaceInstUsesWith(*I, ConstantInt::get(I->getType(), DontKnow)); + } } eraseInstFromFunction(*I); } diff --git a/test/Transforms/InstCombine/builtin-object-size-ptr.ll b/test/Transforms/InstCombine/builtin-object-size-ptr.ll deleted file mode 100644 index b38513999dc..00000000000 --- a/test/Transforms/InstCombine/builtin-object-size-ptr.ll +++ /dev/null @@ -1,34 +0,0 @@ -; RUN: opt -instcombine -S < %s | FileCheck %s - -; int foo() { -; struct V { char buf1[10]; -; int b; -; char buf2[10]; -; } var; -; -; char *p = &var.buf1[1]; -; return __builtin_object_size (p, 0); -; } - -%struct.V = type { [10 x i8], i32, [10 x i8] } - -define i32 @foo() #0 { -entry: - %var = alloca %struct.V, align 4 - %0 = bitcast %struct.V* %var to i8* - call void @llvm.lifetime.start(i64 28, i8* %0) #3 - %buf1 = getelementptr inbounds %struct.V, %struct.V* %var, i32 0, i32 0 - %arrayidx = getelementptr inbounds [10 x i8], [10 x i8]* %buf1, i64 0, i64 1 - %1 = call i64 @llvm.objectsize.i64.p0i8(i8* %arrayidx, i1 false) - %conv = trunc i64 %1 to i32 - call void @llvm.lifetime.end(i64 28, i8* %0) #3 - ret i32 %conv -; CHECK: ret i32 27 -; CHECK-NOT: ret i32 -1 -} - -declare void @llvm.lifetime.start(i64, i8* nocapture) #1 - -declare i64 @llvm.objectsize.i64.p0i8(i8*, i1) #2 - -declare void @llvm.lifetime.end(i64, i8* nocapture) #1 -- 2.11.0