[llvm] r302447 - ConstantFold: Handle gep nonnull, undef as well
Daniel Berlin via llvm-commits
llvm-commits at lists.llvm.org
Mon May 8 10:37:33 PDT 2017
Author: dannyb
Date: Mon May 8 12:37:33 2017
New Revision: 302447
URL: http://llvm.org/viewvc/llvm-project?rev=302447&view=rev
Log:
ConstantFold: Handle gep nonnull, undef as well
Modified:
llvm/trunk/lib/IR/ConstantFold.cpp
llvm/trunk/test/Transforms/Inline/inline-constexpr-addrspacecast-argument.ll
Modified: llvm/trunk/lib/IR/ConstantFold.cpp
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/lib/IR/ConstantFold.cpp?rev=302447&r1=302446&r2=302447&view=diff
==============================================================================
--- llvm/trunk/lib/IR/ConstantFold.cpp (original)
+++ llvm/trunk/lib/IR/ConstantFold.cpp Mon May 8 12:37:33 2017
@@ -2041,9 +2041,6 @@ Constant *llvm::ConstantFoldGetElementPt
Optional<unsigned> InRangeIndex,
ArrayRef<Value *> Idxs) {
if (Idxs.empty()) return C;
- Constant *Idx0 = cast<Constant>(Idxs[0]);
- if ((Idxs.size() == 1 && Idx0->isNullValue()))
- return C;
if (isa<UndefValue>(C)) {
Type *GEPTy = GetElementPtrInst::getGEPReturnType(
@@ -2051,6 +2048,10 @@ Constant *llvm::ConstantFoldGetElementPt
return UndefValue::get(GEPTy);
}
+ Constant *Idx0 = cast<Constant>(Idxs[0]);
+ if (Idxs.size() == 1 && (Idx0->isNullValue() || isa<UndefValue>(Idx0)))
+ return C;
+
if (C->isNullValue()) {
bool isNull = true;
for (unsigned i = 0, e = Idxs.size(); i != e; ++i)
Modified: llvm/trunk/test/Transforms/Inline/inline-constexpr-addrspacecast-argument.ll
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/test/Transforms/Inline/inline-constexpr-addrspacecast-argument.ll?rev=302447&r1=302446&r2=302447&view=diff
==============================================================================
--- llvm/trunk/test/Transforms/Inline/inline-constexpr-addrspacecast-argument.ll (original)
+++ llvm/trunk/test/Transforms/Inline/inline-constexpr-addrspacecast-argument.ll Mon May 8 12:37:33 2017
@@ -6,7 +6,7 @@ target datalayout = "e-p3:32:32-p4:64:64
@lds = internal addrspace(3) global [64 x i64] zeroinitializer
; CHECK-LABEL: @constexpr_addrspacecast_ptr_size_change(
-; CHECK: load i64, i64 addrspace(4)* getelementptr (i64, i64 addrspace(4)* addrspacecast (i64 addrspace(3)* getelementptr inbounds ([64 x i64], [64 x i64] addrspace(3)* @lds, i32 0, i32 0) to i64 addrspace(4)*), i64 undef)
+; CHECK: load i64, i64 addrspace(4)* addrspacecast (i64 addrspace(3)* getelementptr inbounds ([64 x i64], [64 x i64] addrspace(3)* @lds, i32 0, i32 0) to i64 addrspace(4)*)
; CHECK-NEXT: br
define void @constexpr_addrspacecast_ptr_size_change() #0 {
%tmp0 = call i32 @foo(i64 addrspace(4)* addrspacecast (i64 addrspace(3)* getelementptr inbounds ([64 x i64], [64 x i64] addrspace(3)* @lds, i32 0, i32 0) to i64 addrspace(4)*)) #1
More information about the llvm-commits
mailing list