Skip to content

Commit d74b1f0

Browse files
authored
ValueTracking: Do not return nullptr from getUnderlyingObject (#115258)
Fixup for 29a5c05. The failure case should return the last value found.
1 parent 24e2e25 commit d74b1f0

File tree

2 files changed

+18
-3
lines changed

2 files changed

+18
-3
lines changed

llvm/lib/Analysis/ValueTracking.cpp

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -6723,9 +6723,10 @@ static bool isSameUnderlyingObjectInLoop(const PHINode *PN,
67236723
const Value *llvm::getUnderlyingObject(const Value *V, unsigned MaxLookup) {
67246724
for (unsigned Count = 0; MaxLookup == 0 || Count < MaxLookup; ++Count) {
67256725
if (auto *GEP = dyn_cast<GEPOperator>(V)) {
6726-
V = GEP->getPointerOperand();
6727-
if (!V->getType()->isPointerTy()) // Only handle scalar pointer base.
6728-
return nullptr;
6726+
const Value *PtrOp = GEP->getPointerOperand();
6727+
if (!PtrOp->getType()->isPointerTy()) // Only handle scalar pointer base.
6728+
return V;
6729+
V = PtrOp;
67296730
} else if (Operator::getOpcode(V) == Instruction::BitCast ||
67306731
Operator::getOpcode(V) == Instruction::AddrSpaceCast) {
67316732
Value *NewV = cast<Operator>(V)->getOperand(0);
Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
; NOTE: Assertions have been autogenerated by utils/update_test_checks.py UTC_ARGS: --version 5
2+
; RUN: opt -S -passes=function-attrs < %s | FileCheck %s
3+
4+
define double @getUnderlyingObject_vector_ptr(<4 x i1> %arg0, <4 x i1> %arg1) {
5+
; CHECK-LABEL: define double @getUnderlyingObject_vector_ptr(
6+
; CHECK-SAME: <4 x i1> [[ARG0:%.*]], <4 x i1> [[ARG1:%.*]]) #[[ATTR0:[0-9]+]] {
7+
; CHECK-NEXT: [[GATHER:%.*]] = tail call <4 x double> @llvm.masked.gather.v4f64.v4p0(<4 x ptr> getelementptr inbounds (i8, <4 x ptr> zeroinitializer, <4 x i64> splat (i64 8)), i32 0, <4 x i1> [[ARG0]], <4 x double> zeroinitializer)
8+
; CHECK-NEXT: [[REDUCE_FADD:%.*]] = tail call double @llvm.vector.reduce.fadd.v4f64(double 0.000000e+00, <4 x double> [[GATHER]])
9+
; CHECK-NEXT: ret double [[REDUCE_FADD]]
10+
;
11+
%gather = tail call <4 x double> @llvm.masked.gather.v4f64.v4p0(<4 x ptr> getelementptr inbounds (i8, <4 x ptr> zeroinitializer, <4 x i64> <i64 8, i64 8, i64 8, i64 8>), i32 0, <4 x i1> %arg0, <4 x double> zeroinitializer)
12+
%reduce.fadd = tail call double @llvm.vector.reduce.fadd.v4f64(double 0.000000e+00, <4 x double> %gather)
13+
ret double %reduce.fadd
14+
}

0 commit comments

Comments
 (0)