Skip to content
Closed
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 4 additions & 0 deletions llvm/lib/Analysis/ValueTracking.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -6661,6 +6661,10 @@ const Value *llvm::getUnderlyingObject(const Value *V, unsigned MaxLookup) {
if (!NewV->getType()->isPointerTy())
return V;
V = NewV;
} else if (Operator::getOpcode(V) == Instruction::IntToPtr &&
Operator::getOpcode(cast<Operator>(V)->getOperand(0)) ==
Instruction::PtrToInt) {
V = cast<Operator>(cast<Operator>(V)->getOperand(0))->getOperand(0);
} else if (auto *GA = dyn_cast<GlobalAlias>(V)) {
if (GA->isInterposable())
return V;
Expand Down
12 changes: 12 additions & 0 deletions llvm/unittests/Analysis/ValueTrackingTest.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -3350,6 +3350,18 @@ TEST_F(ValueTrackingTest, ComputeConstantRange) {
}
}

TEST_F(ValueTrackingTest, GetUnderlyingObject) {
parseAssembly(R"(
@globalmem = external global i8
define void @test() {
%A = getelementptr i8, ptr @globalmem, i64 0
%A2 = getelementptr i8, ptr inttoptr (i32 ptrtoint (ptr @globalmem to i32) to ptr), i64 0
ret void
}
)");
EXPECT_EQ(getUnderlyingObject(A), getUnderlyingObject(A2));
}

struct FindAllocaForValueTestParams {
const char *IR;
bool AnyOffsetResult;
Expand Down
Loading