Skip to content

Commit

Permalink
Merged master:b7e2358220f into amd-gfx:e9e04d625cc
Browse files Browse the repository at this point in the history
Local branch amd-gfx e9e04d6 Merged master:ff6a0b6a8ee into amd-gfx:9f5a06205c0
Remote branch master b7e2358 Remove getNumUses() comparisons (NFC)
  • Loading branch information
Sw authored and Sw committed May 2, 2020
2 parents e9e04d6 + b7e2358 commit 1b19d46
Show file tree
Hide file tree
Showing 8 changed files with 58 additions and 8 deletions.
2 changes: 1 addition & 1 deletion llvm/include/llvm/IR/AbstractCallSite.h
Original file line number Diff line number Diff line change
Expand Up @@ -144,7 +144,7 @@ class AbstractCallSite {
// If the use is actually in a constant cast expression which itself
// has only one use, we look through the constant cast expression.
if (auto *CE = dyn_cast<ConstantExpr>(U->getUser()))
if (CE->getNumUses() == 1 && CE->isCast())
if (CE->hasOneUse() && CE->isCast())
U = &*CE->use_begin();

return (int)CB->getArgOperandNo(U) == CI.ParameterEncoding[0];
Expand Down
2 changes: 1 addition & 1 deletion llvm/lib/IR/AbstractCallSite.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -64,7 +64,7 @@ AbstractCallSite::AbstractCallSite(const Use *U)
// This happens by updating the use @p U to the use of the constant
// cast expression and afterwards re-initializing CB accordingly.
if (ConstantExpr *CE = dyn_cast<ConstantExpr>(U->getUser()))
if (CE->getNumUses() == 1 && CE->isCast()) {
if (CE->hasOneUse() && CE->isCast()) {
U = &*CE->use_begin();
CB = dyn_cast<CallBase>(U->getUser());
}
Expand Down
2 changes: 1 addition & 1 deletion llvm/lib/Transforms/Coroutines/CoroSplit.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -584,7 +584,7 @@ void CoroCloner::replaceEntryBlock() {
// Move any allocas into Entry that weren't moved into the frame.
for (auto IT = OldEntry->begin(), End = OldEntry->end(); IT != End;) {
Instruction &I = *IT++;
if (!isa<AllocaInst>(&I) || I.getNumUses() == 0)
if (!isa<AllocaInst>(&I) || I.use_empty())
continue;

I.moveBefore(*Entry, Entry->getFirstInsertionPt());
Expand Down
2 changes: 1 addition & 1 deletion llvm/lib/Transforms/IPO/Attributor.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1293,7 +1293,7 @@ static void createShallowWrapper(Function &F) {
F.setLinkage(GlobalValue::InternalLinkage);

F.replaceAllUsesWith(Wrapper);
assert(F.getNumUses() == 0 && "Uses remained after wrapper was created!");
assert(F.use_empty() && "Uses remained after wrapper was created!");

// Move the COMDAT section to the wrapper.
// TODO: Check if we need to keep it for F as well.
Expand Down
6 changes: 3 additions & 3 deletions llvm/lib/Transforms/IPO/AttributorAttributes.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -897,7 +897,7 @@ ChangeStatus AAReturnedValuesImpl::manifest(Attributor &A) {

// Callback to replace the uses of CB with the constant C.
auto ReplaceCallSiteUsersWith = [&A](CallBase &CB, Constant &C) {
if (CB.getNumUses() == 0)
if (CB.use_empty())
return ChangeStatus::UNCHANGED;
if (A.changeValueAfterManifest(CB, C))
return ChangeStatus::CHANGED;
Expand Down Expand Up @@ -2267,7 +2267,7 @@ struct AANoAliasFloating final : AANoAliasImpl {
if (!CI)
break;
Value *Base = CI->getOperand(0);
if (Base->getNumUses() != 1)
if (!Base->hasOneUse())
break;
Val = Base;
} while (true);
Expand Down Expand Up @@ -2451,7 +2451,7 @@ struct AANoAliasCallSiteArgument final : AANoAliasImpl {
Instruction *UserI = cast<Instruction>(U.getUser());

// If user if curr instr and only use.
if ((UserI == getCtxI()) && (UserI->getNumUses() == 1))
if (UserI == getCtxI() && UserI->hasOneUse())
return true;

const Function *ScopeFn = VIRP.getAnchorScope();
Expand Down
2 changes: 1 addition & 1 deletion llvm/lib/Transforms/Scalar/SeparateConstOffsetFromGEP.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -704,7 +704,7 @@ Value *ConstantOffsetExtractor::removeConstOffset(unsigned ChainIndex) {
}

BinaryOperator *BO = cast<BinaryOperator>(UserChain[ChainIndex]);
assert(BO->getNumUses() <= 1 &&
assert((BO->use_empty() || BO->hasOneUse()) &&
"distributeExtsAndCloneChain clones each BinaryOperator in "
"UserChain, so no one should be used more than "
"once");
Expand Down
10 changes: 10 additions & 0 deletions llvm/lib/Transforms/Utils/FunctionComparator.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -656,6 +656,16 @@ int FunctionComparator::cmpOperations(const Instruction *L,
return cmpNumbers(RMWI->getSyncScopeID(),
cast<AtomicRMWInst>(R)->getSyncScopeID());
}
if (const ShuffleVectorInst *SVI = dyn_cast<ShuffleVectorInst>(L)) {
ArrayRef<int> LMask = SVI->getShuffleMask();
ArrayRef<int> RMask = cast<ShuffleVectorInst>(R)->getShuffleMask();
if (int Res = cmpNumbers(LMask.size(), RMask.size()))
return Res;
for (size_t i = 0, e = LMask.size(); i != e; ++i) {
if (int Res = cmpNumbers(LMask[i], RMask[i]))
return Res;
}
}
if (const PHINode *PNL = dyn_cast<PHINode>(L)) {
const PHINode *PNR = cast<PHINode>(R);
// Ensure that in addition to the incoming values being identical
Expand Down
40 changes: 40 additions & 0 deletions llvm/test/Transforms/MergeFunc/shufflevector.ll
Original file line number Diff line number Diff line change
@@ -0,0 +1,40 @@
; NOTE: Assertions have been autogenerated by utils/update_test_checks.py
; RUN: opt -S -mergefunc < %s | FileCheck %s

define internal <2 x i32> @test1(<2 x i32> %v1, <2 x i32> %v2) {
; CHECK-LABEL: @test1(
; CHECK-NEXT: [[X:%.*]] = shufflevector <2 x i32> [[V1:%.*]], <2 x i32> [[V2:%.*]], <2 x i32> <i32 0, i32 1>
; CHECK-NEXT: ret <2 x i32> [[X]]
;
%x = shufflevector <2 x i32> %v1, <2 x i32> %v2, <2 x i32> <i32 0, i32 1>
ret <2 x i32> %x
}

; Same mask as test1.
define internal <2 x i32> @test2(<2 x i32> %v1, <2 x i32> %v2) {
%x = shufflevector <2 x i32> %v1, <2 x i32> %v2, <2 x i32> <i32 0, i32 1>
ret <2 x i32> %x
}

; Different mask than test1, don't merge.
define internal <2 x i32> @test3(<2 x i32> %v1, <2 x i32> %v2) {
; CHECK-LABEL: @test3(
; CHECK-NEXT: [[X:%.*]] = shufflevector <2 x i32> [[V1:%.*]], <2 x i32> [[V2:%.*]], <2 x i32> <i32 1, i32 0>
; CHECK-NEXT: ret <2 x i32> [[X]]
;
%x = shufflevector <2 x i32> %v1, <2 x i32> %v2, <2 x i32> <i32 1, i32 0>
ret <2 x i32> %x
}

define void @caller(<2 x i32> %v1, <2 x i32> %v2) {
; CHECK-LABEL: @caller(
; CHECK-NEXT: [[TMP1:%.*]] = call <2 x i32> @test1(<2 x i32> [[V1:%.*]], <2 x i32> [[V2:%.*]])
; CHECK-NEXT: [[TMP2:%.*]] = call <2 x i32> @test1(<2 x i32> [[V1]], <2 x i32> [[V2]])
; CHECK-NEXT: [[TMP3:%.*]] = call <2 x i32> @test3(<2 x i32> [[V1]], <2 x i32> [[V2]])
; CHECK-NEXT: ret void
;
call <2 x i32> @test1(<2 x i32> %v1, <2 x i32> %v2)
call <2 x i32> @test2(<2 x i32> %v1, <2 x i32> %v2)
call <2 x i32> @test3(<2 x i32> %v1, <2 x i32> %v2)
ret void
}

0 comments on commit 1b19d46

Please sign in to comment.