@@ -1115,9 +1115,10 @@ bool AMDGPUPromoteAllocaImpl::binaryOpIsDerivedFromSameAlloca(
1115
1115
if (Val == OtherOp)
1116
1116
OtherOp = Inst->getOperand (OpIdx1);
1117
1117
1118
- if (isa<ConstantPointerNull>(OtherOp))
1118
+ if (isa<ConstantPointerNull, ConstantAggregateZero >(OtherOp))
1119
1119
return true ;
1120
1120
1121
+ // TODO: getUnderlyingObject will not work on a vector getelementptr
1121
1122
Value *OtherObj = getUnderlyingObject (OtherOp);
1122
1123
if (!isa<AllocaInst>(OtherObj))
1123
1124
return false ;
@@ -1195,36 +1196,19 @@ bool AMDGPUPromoteAllocaImpl::collectUsesWithPtrTypes(
1195
1196
continue ;
1196
1197
}
1197
1198
1198
- // TODO: If we know the address is only observed through flat pointers, we
1199
- // could still promote.
1200
- if (UseInst->getOpcode () == Instruction::AddrSpaceCast)
1201
- return false ;
1202
-
1203
- // Do not promote vector/aggregate type instructions. It is hard to track
1204
- // their users.
1205
- if (isa<InsertValueInst>(User) || isa<InsertElementInst>(User))
1206
- return false ;
1207
-
1208
- // TODO: Handle vectors of pointers.
1209
- if (!User->getType ()->isPointerTy ())
1210
- return false ;
1211
-
1212
1199
if (GetElementPtrInst *GEP = dyn_cast<GetElementPtrInst>(UseInst)) {
1213
1200
// Be conservative if an address could be computed outside the bounds of
1214
1201
// the alloca.
1215
1202
if (!GEP->isInBounds ())
1216
1203
return false ;
1217
- }
1218
-
1219
- // Only promote a select if we know that the other select operand is from
1220
- // another pointer that will also be promoted.
1221
- if (SelectInst *SI = dyn_cast<SelectInst>(UseInst)) {
1204
+ } else if (SelectInst *SI = dyn_cast<SelectInst>(UseInst)) {
1205
+ // Only promote a select if we know that the other select operand is from
1206
+ // another pointer that will also be promoted.
1222
1207
if (!binaryOpIsDerivedFromSameAlloca (BaseAlloca, Val, SI, 1 , 2 ))
1223
1208
return false ;
1224
- }
1209
+ } else if (PHINode *Phi = dyn_cast<PHINode>(UseInst)) {
1210
+ // Repeat for phis.
1225
1211
1226
- // Repeat for phis.
1227
- if (PHINode *Phi = dyn_cast<PHINode>(UseInst)) {
1228
1212
// TODO: Handle more complex cases. We should be able to replace loops
1229
1213
// over arrays.
1230
1214
switch (Phi->getNumIncomingValues ()) {
@@ -1237,6 +1221,15 @@ bool AMDGPUPromoteAllocaImpl::collectUsesWithPtrTypes(
1237
1221
default :
1238
1222
return false ;
1239
1223
}
1224
+ } else if (!isa<ExtractElementInst>(User)) {
1225
+ // Do not promote vector/aggregate type instructions. It is hard to track
1226
+ // their users.
1227
+
1228
+ // Do not promote addrspacecast.
1229
+ //
1230
+ // TODO: If we know the address is only observed through flat pointers, we
1231
+ // could still promote.
1232
+ return false ;
1240
1233
}
1241
1234
1242
1235
WorkList.push_back (User);
@@ -1490,17 +1483,21 @@ bool AMDGPUPromoteAllocaImpl::tryPromoteAllocaToLDS(AllocaInst &I,
1490
1483
1491
1484
SmallVector<IntrinsicInst *> DeferredIntrs;
1492
1485
1486
+ PointerType *NewPtrTy = PointerType::get (Context, AMDGPUAS::LOCAL_ADDRESS);
1487
+
1493
1488
for (Value *V : WorkList) {
1494
1489
CallInst *Call = dyn_cast<CallInst>(V);
1495
1490
if (!Call) {
1496
1491
if (ICmpInst *CI = dyn_cast<ICmpInst>(V)) {
1497
- PointerType *NewTy = PointerType::get (Context, AMDGPUAS::LOCAL_ADDRESS);
1492
+ Value *LHS = CI->getOperand (0 );
1493
+ Value *RHS = CI->getOperand (1 );
1498
1494
1499
- if (isa<ConstantPointerNull>(CI->getOperand (0 )))
1500
- CI->setOperand (0 , ConstantPointerNull::get (NewTy));
1495
+ Type *NewTy = LHS->getType ()->getWithNewType (NewPtrTy);
1496
+ if (isa<ConstantPointerNull, ConstantAggregateZero>(LHS))
1497
+ CI->setOperand (0 , Constant::getNullValue (NewTy));
1501
1498
1502
- if (isa<ConstantPointerNull>(CI-> getOperand ( 1 ) ))
1503
- CI->setOperand (1 , ConstantPointerNull::get (NewTy));
1499
+ if (isa<ConstantPointerNull, ConstantAggregateZero>(RHS ))
1500
+ CI->setOperand (1 , Constant::getNullValue (NewTy));
1504
1501
1505
1502
continue ;
1506
1503
}
@@ -1510,25 +1507,23 @@ bool AMDGPUPromoteAllocaImpl::tryPromoteAllocaToLDS(AllocaInst &I,
1510
1507
if (isa<AddrSpaceCastInst>(V))
1511
1508
continue ;
1512
1509
1513
- PointerType *NewTy = PointerType::get (Context, AMDGPUAS::LOCAL_ADDRESS);
1514
-
1515
- assert (isa<PointerType>(V->getType ()));
1510
+ assert (V->getType ()->isPtrOrPtrVectorTy ());
1516
1511
1517
- // FIXME: It doesn't really make sense to try to do this for all
1518
- // instructions.
1512
+ Type *NewTy = V->getType ()->getWithNewType (NewPtrTy);
1519
1513
V->mutateType (NewTy);
1520
1514
1521
1515
// Adjust the types of any constant operands.
1522
1516
if (SelectInst *SI = dyn_cast<SelectInst>(V)) {
1523
- if (isa<ConstantPointerNull>(SI->getOperand (1 )))
1524
- SI->setOperand (1 , ConstantPointerNull::get (NewTy));
1517
+ if (isa<ConstantPointerNull, ConstantAggregateZero >(SI->getOperand (1 )))
1518
+ SI->setOperand (1 , Constant::getNullValue (NewTy));
1525
1519
1526
- if (isa<ConstantPointerNull>(SI->getOperand (2 )))
1527
- SI->setOperand (2 , ConstantPointerNull::get (NewTy));
1520
+ if (isa<ConstantPointerNull, ConstantAggregateZero >(SI->getOperand (2 )))
1521
+ SI->setOperand (2 , Constant::getNullValue (NewTy));
1528
1522
} else if (PHINode *Phi = dyn_cast<PHINode>(V)) {
1529
1523
for (unsigned I = 0 , E = Phi->getNumIncomingValues (); I != E; ++I) {
1530
- if (isa<ConstantPointerNull>(Phi->getIncomingValue (I)))
1531
- Phi->setIncomingValue (I, ConstantPointerNull::get (NewTy));
1524
+ if (isa<ConstantPointerNull, ConstantAggregateZero>(
1525
+ Phi->getIncomingValue (I)))
1526
+ Phi->setIncomingValue (I, Constant::getNullValue (NewTy));
1532
1527
}
1533
1528
}
1534
1529
0 commit comments