@@ -1002,70 +1002,49 @@ bool InferAddressSpacesImpl::updateAddressSpace(
1002
1002
// isAddressExpression should guarantee that V is an operator or an argument.
1003
1003
assert (isa<Operator>(V) || isa<Argument>(V));
1004
1004
1005
- if (isa<Operator>(V) &&
1006
- cast<Operator>(V).getOpcode () == Instruction::Select) {
1007
- const Operator &Op = cast<Operator>(V);
1008
- Value *Src0 = Op.getOperand (1 );
1009
- Value *Src1 = Op.getOperand (2 );
1010
-
1011
- auto I = InferredAddrSpace.find (Src0);
1012
- unsigned Src0AS = (I != InferredAddrSpace.end ())
1013
- ? I->second
1014
- : Src0->getType ()->getPointerAddressSpace ();
1015
-
1016
- auto J = InferredAddrSpace.find (Src1);
1017
- unsigned Src1AS = (J != InferredAddrSpace.end ())
1018
- ? J->second
1019
- : Src1->getType ()->getPointerAddressSpace ();
1020
-
1021
- auto *C0 = dyn_cast<Constant>(Src0);
1022
- auto *C1 = dyn_cast<Constant>(Src1);
1023
-
1024
- // If one of the inputs is a constant, we may be able to do a constant
1025
- // addrspacecast of it. Defer inferring the address space until the input
1026
- // address space is known.
1027
- if ((C1 && Src0AS == UninitializedAddressSpace) ||
1028
- (C0 && Src1AS == UninitializedAddressSpace))
1029
- return false ;
1030
-
1031
- if (C0 && isSafeToCastConstAddrSpace (C0, Src1AS))
1032
- NewAS = Src1AS;
1033
- else if (C1 && isSafeToCastConstAddrSpace (C1, Src0AS))
1034
- NewAS = Src0AS;
1035
- else
1036
- NewAS = joinAddressSpaces (Src0AS, Src1AS);
1005
+ unsigned AS = TTI->getAssumedAddrSpace (&V);
1006
+ if (AS != UninitializedAddressSpace) {
1007
+ // Use the assumed address space directly.
1008
+ NewAS = AS;
1037
1009
} else {
1038
- unsigned AS = TTI->getAssumedAddrSpace (&V);
1039
- if (AS != UninitializedAddressSpace) {
1040
- // Use the assumed address space directly.
1041
- NewAS = AS;
1042
- } else {
1043
- // Otherwise, infer the address space from its pointer operands.
1044
- for (Value *PtrOperand : getPointerOperands (V, *DL, TTI)) {
1045
- auto I = InferredAddrSpace.find (PtrOperand);
1046
- unsigned OperandAS;
1047
- if (I == InferredAddrSpace.end ()) {
1048
- OperandAS = PtrOperand->getType ()->getPointerAddressSpace ();
1049
- if (OperandAS == FlatAddrSpace) {
1050
- // Check AC for assumption dominating V.
1051
- unsigned AS = getPredicatedAddrSpace (*PtrOperand, &V);
1052
- if (AS != UninitializedAddressSpace) {
1053
- LLVM_DEBUG (dbgs ()
1054
- << " deduce operand AS from the predicate addrspace "
1055
- << AS << ' \n ' );
1056
- OperandAS = AS;
1057
- // Record this use with the predicated AS.
1058
- PredicatedAS[std::make_pair (&V, PtrOperand)] = OperandAS;
1059
- }
1010
+ // Otherwise, infer the address space from its pointer operands.
1011
+ SmallVector<Constant *, 2 > ConstantPtrOps;
1012
+ for (Value *PtrOperand : getPointerOperands (V, *DL, TTI)) {
1013
+ auto I = InferredAddrSpace.find (PtrOperand);
1014
+ unsigned OperandAS;
1015
+ if (I == InferredAddrSpace.end ()) {
1016
+ OperandAS = PtrOperand->getType ()->getPointerAddressSpace ();
1017
+ if (auto *C = dyn_cast<Constant>(PtrOperand);
1018
+ C && OperandAS == FlatAddrSpace) {
1019
+ // Defer joining the address space of constant pointer operands.
1020
+ ConstantPtrOps.push_back (C);
1021
+ continue ;
1022
+ }
1023
+ if (OperandAS == FlatAddrSpace) {
1024
+ // Check AC for assumption dominating V.
1025
+ unsigned AS = getPredicatedAddrSpace (*PtrOperand, &V);
1026
+ if (AS != UninitializedAddressSpace) {
1027
+ LLVM_DEBUG (dbgs ()
1028
+ << " deduce operand AS from the predicate addrspace "
1029
+ << AS << ' \n ' );
1030
+ OperandAS = AS;
1031
+ // Record this use with the predicated AS.
1032
+ PredicatedAS[std::make_pair (&V, PtrOperand)] = OperandAS;
1060
1033
}
1061
- } else
1062
- OperandAS = I->second ;
1034
+ }
1035
+ } else
1036
+ OperandAS = I->second ;
1063
1037
1064
- // join(flat, *) = flat. So we can break if NewAS is already flat.
1065
- NewAS = joinAddressSpaces (NewAS, OperandAS);
1066
- if (NewAS == FlatAddrSpace)
1067
- break ;
1068
- }
1038
+ // join(flat, *) = flat. So we can break if NewAS is already flat.
1039
+ NewAS = joinAddressSpaces (NewAS, OperandAS);
1040
+ if (NewAS == FlatAddrSpace)
1041
+ break ;
1042
+ }
1043
+ if (NewAS != FlatAddrSpace && NewAS != UninitializedAddressSpace) {
1044
+ if (any_of (ConstantPtrOps, [=](Constant *C) {
1045
+ return !isSafeToCastConstAddrSpace (C, NewAS);
1046
+ }))
1047
+ NewAS = FlatAddrSpace;
1069
1048
}
1070
1049
}
1071
1050
0 commit comments