Index: lib/Target/ARM/ARMCodeGenPrepare.cpp =================================================================== --- lib/Target/ARM/ARMCodeGenPrepare.cpp +++ lib/Target/ARM/ARMCodeGenPrepare.cpp @@ -175,7 +175,6 @@ /// dealing with icmps but allow any other integer that is <= 16 bits. Void /// types are accepted so we can handle switches. static bool isSupportedType(Value *V) { - LLVM_DEBUG(dbgs() << "ARM CGP: isSupportedType: " << *V << "\n"); Type *Ty = V->getType(); // Allow voids and pointers, these won't be promoted. @@ -186,10 +185,8 @@ Ty = cast(Ld->getPointerOperandType())->getElementType(); const IntegerType *IntTy = dyn_cast(Ty); - if (!IntTy) { - LLVM_DEBUG(dbgs() << "ARM CGP: No, not an integer.\n"); + if (!IntTy) return false; - } return IntTy->getBitWidth() == ARMCodeGenPrepare::TypeSize; } @@ -204,7 +201,7 @@ static bool isSource(Value *V) { if (!isa(V->getType())) return false; - // TODO Allow truncs and zext to be sources. + // TODO Allow zext to be sources. if (isa(V)) return true; else if (isa(V)) @@ -213,6 +210,8 @@ return true; else if (auto *Call = dyn_cast(V)) return Call->hasRetAttr(Attribute::AttrKind::ZExt); + else if (auto *Trunc = dyn_cast(V)) + return isSupportedType(Trunc); return false; } @@ -282,10 +281,8 @@ } static bool shouldPromote(Value *V) { - if (!isa(V->getType()) || isSink(V)) { - LLVM_DEBUG(dbgs() << "ARM CGP: Don't need to promote: " << *V << "\n"); + if (!isa(V->getType()) || isSink(V)) return false; - } if (isSource(V)) return true; @@ -365,7 +362,7 @@ Users.push_back(User); } - for (auto &U : Users) + for (auto *U : Users) U->replaceUsesOfWith(From, To); }; @@ -519,6 +516,15 @@ } } LLVM_DEBUG(dbgs() << "ARM CGP: Mutation complete:\n"); + LLVM_DEBUG(dbgs(); + for (auto *V : Sources) + V->dump(); + for (auto *I : NewInsts) + I->dump(); + for (auto *V : Visited) { + if (!Sources.count(V)) + V->dump(); + }); } /// We accept most instructions, as well as Arguments and ConstantInsts. We @@ -526,8 +532,6 @@ /// return value is zeroext. We don't allow opcodes that can introduce sign /// bits. bool ARMCodeGenPrepare::isSupportedValue(Value *V) { - LLVM_DEBUG(dbgs() << "ARM CGP: Is " << *V << " supported?\n"); - if (isa(V)) return true; @@ -547,7 +551,11 @@ isa(V)) return isSupportedType(V); - if (isa(V) && !isa(V)) + // Truncs can be either sources or sinks. + if (auto *Trunc = dyn_cast(V)) + return isSupportedType(Trunc) || isSupportedType(Trunc->getOperand(0)); + + if (isa(V) && !isa(V)) return isSupportedType(cast(V)->getOperand(0)); // Special cases for calls as we need to check for zeroext @@ -557,10 +565,9 @@ return isSupportedType(Call) && Call->hasRetAttr(Attribute::AttrKind::ZExt); - if (!isa(V)) { - LLVM_DEBUG(dbgs() << "ARM CGP: No, not a binary operator.\n"); + if (!isa(V)) return false; - } + if (!isSupportedType(V)) return false; @@ -662,10 +669,8 @@ // the tree has already been explored. // TODO: This could limit the transform, ie if we try to promote something // from an i8 and fail first, before trying an i16. - if (AllVisited.count(V)) { - LLVM_DEBUG(dbgs() << "ARM CGP: Already visited this: " << *V << "\n"); + if (AllVisited.count(V)) return false; - } CurrentVisited.insert(V); AllVisited.insert(V); @@ -745,7 +750,6 @@ if (CI.isSigned() || !isa(CI.getOperand(0)->getType())) continue; - LLVM_DEBUG(dbgs() << "ARM CGP: Searching from: " << CI << "\n"); for (auto &Op : CI.operands()) { if (auto *I = dyn_cast(Op)) MadeChange |= TryToPromote(I); Index: test/CodeGen/ARM/arm-cgp-casts.ll =================================================================== --- test/CodeGen/ARM/arm-cgp-casts.ll +++ test/CodeGen/ARM/arm-cgp-casts.ll @@ -190,7 +190,6 @@ ; CHECK-COMMON-LABEL: phi_feeding_switch ; CHECK-COMMON: ldrb ; CHECK-COMMON: uxtb -; CHECK-COMMON: uxtb define void @phi_feeding_switch(i8* %memblock, i8* %store, i16 %arg) { entry: %pre = load i8, i8* %memblock, align 1