parseAssemblyString("target datalayout = "
"\"e-m:e-p270:32:32-p271:32:32-p272:64:64-i64:64-f80:"
"128-n8:16:32:64-S128-ni:1-p2:32:8:8:32-ni:2\""
- "define float addrspace(1)* @test(i64 %offset) { "
- " %ptr = getelementptr inbounds float, float "
- "addrspace(1)* null, i64 %offset"
- " ret float addrspace(1)* %ptr"
+ "define ptr addrspace(1) @test(i64 %offset) { "
+ " %ptr = getelementptr inbounds float, ptr "
+ "addrspace(1) null, i64 %offset"
+ " ret ptr addrspace(1) %ptr"
"}",
Err, C);
I.replaceAllUsesWith(V);
// Check that the expander created:
- // define float addrspace(1)* @test(i64 %off) {
- // %scevgep = getelementptr float, float addrspace(1)* null, i64 %off
- // %scevgep1 = bitcast float addrspace(1)* %scevgep to i8 addrspace(1)*
- // %uglygep = getelementptr i8, i8 addrspace(1)* %scevgep1, i64 1
- // %uglygep2 = bitcast i8 addrspace(1)* %uglygep to float addrspace(1)*
- // %ptr = getelementptr inbounds float, float addrspace(1)* null, i64 %off
- // ret float addrspace(1)* %uglygep2
+ // define ptr addrspace(1) @test(i64 %off) {
+ // %1 = shl i64 %offset, 2
+ // %2 = add nuw nsw i64 %1, 1
+ // %uglygep = getelementptr i8, ptr addrspace(1) null, i64 %2
+ // %ptr = getelementptr inbounds float, ptr addrspace(1) null, i64 %off
+ // ret ptr addrspace(1) %uglygep
// }
- auto *Cast = dyn_cast<BitCastInst>(V);
- EXPECT_TRUE(Cast);
- EXPECT_EQ(Cast->getType(), I.getType());
- auto *GEP = dyn_cast<GetElementPtrInst>(Cast->getOperand(0));
+ Value *Offset = &*F.arg_begin();
+ auto *GEP = dyn_cast<GetElementPtrInst>(V);
EXPECT_TRUE(GEP);
- EXPECT_TRUE(match(GEP->getOperand(1), m_SpecificInt(1)));
- auto *Cast1 = dyn_cast<BitCastInst>(GEP->getPointerOperand());
- EXPECT_TRUE(Cast1);
- auto *GEP1 = dyn_cast<GetElementPtrInst>(Cast1->getOperand(0));
- EXPECT_TRUE(GEP1);
- EXPECT_TRUE(cast<Constant>(GEP1->getPointerOperand())->isNullValue());
- EXPECT_EQ(GEP1->getOperand(1), &*F.arg_begin());
- EXPECT_EQ(cast<PointerType>(GEP1->getPointerOperand()->getType())
+ EXPECT_TRUE(cast<Constant>(GEP->getPointerOperand())->isNullValue());
+ EXPECT_EQ(GEP->getNumOperands(), 2);
+ EXPECT_TRUE(match(
+ GEP->getOperand(1),
+ m_Add(m_Shl(m_Specific(Offset), m_SpecificInt(2)), m_SpecificInt(1))));
+ EXPECT_EQ(cast<PointerType>(GEP->getPointerOperand()->getType())
->getAddressSpace(),
cast<PointerType>(I.getType())->getAddressSpace());
EXPECT_FALSE(verifyFunction(F, &errs()));