Skip to content

Commit 4d864c7

Browse files
committed
Fixups + more tests
1 parent 55fbdad commit 4d864c7

File tree

2 files changed

+12
-22
lines changed

2 files changed

+12
-22
lines changed

llvm/lib/Analysis/InstructionSimplify.cpp

Lines changed: 10 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -4284,6 +4284,10 @@ static Value *simplifyWithOpsReplaced(Value *V,
42844284
assert((AllowRefinement || !Q.CanUseUndef) &&
42854285
"If AllowRefinement=false then CanUseUndef=false");
42864286
for (const auto &OpAndRepOp : Ops) {
4287+
// We cannot replace a constant, and shouldn't even try.
4288+
if (isa<Constant>(OpAndRepOp.first))
4289+
return nullptr;
4290+
42874291
// Trivial replacement.
42884292
if (V == OpAndRepOp.first)
42894293
return OpAndRepOp.second;
@@ -4309,30 +4313,20 @@ static Value *simplifyWithOpsReplaced(Value *V,
43094313
if (isa<FreezeInst>(I))
43104314
return nullptr;
43114315

4312-
SmallVector<std::pair<Value *, Value *>> ValidReplacements{};
43134316
for (const auto &OpAndRepOp : Ops) {
4314-
// We cannot replace a constant, and shouldn't even try.
4315-
if (isa<Constant>(OpAndRepOp.first))
4316-
return nullptr;
4317-
43184317
// For vector types, the simplification must hold per-lane, so forbid
43194318
// potentially cross-lane operations like shufflevector.
43204319
if (OpAndRepOp.first->getType()->isVectorTy() &&
43214320
!isNotCrossLaneOperation(I))
4322-
continue;
4323-
ValidReplacements.emplace_back(OpAndRepOp);
4321+
return nullptr;
43244322
}
43254323

4326-
if (ValidReplacements.empty())
4327-
return nullptr;
4328-
43294324
// Replace Op with RepOp in instruction operands.
43304325
SmallVector<Value *, 8> NewOps;
43314326
bool AnyReplaced = false;
43324327
for (Value *InstOp : I->operands()) {
4333-
if (Value *NewInstOp =
4334-
simplifyWithOpsReplaced(InstOp, ValidReplacements, Q,
4335-
AllowRefinement, DropFlags, MaxRecurse)) {
4328+
if (Value *NewInstOp = simplifyWithOpsReplaced(
4329+
InstOp, Ops, Q, AllowRefinement, DropFlags, MaxRecurse)) {
43364330
NewOps.push_back(NewInstOp);
43374331
AnyReplaced = InstOp != NewInstOp;
43384332
} else {
@@ -4383,9 +4377,8 @@ static Value *simplifyWithOpsReplaced(Value *V,
43834377
// by assumption and this case never wraps, so nowrap flags can be
43844378
// ignored.
43854379
if ((Opcode == Instruction::Sub || Opcode == Instruction::Xor) &&
4386-
any_of(ValidReplacements, [=](const auto &Rep) {
4387-
return NewOps[0] == NewOps[1] && NewOps[0] == Rep.second;
4388-
}))
4380+
NewOps[0] == NewOps[1] &&
4381+
any_of(Ops, [=](const auto &Rep) { return NewOps[0] == Rep.second; }))
43894382
return Constant::getNullValue(I->getType());
43904383

43914384
// If we are substituting an absorber constant into a binop and extra
@@ -4397,7 +4390,7 @@ static Value *simplifyWithOpsReplaced(Value *V,
43974390
// (Op == -1) ? -1 : (Op | (binop C, Op) --> Op | (binop C, Op)
43984391
Constant *Absorber = ConstantExpr::getBinOpAbsorber(Opcode, I->getType());
43994392
if ((NewOps[0] == Absorber || NewOps[1] == Absorber) &&
4400-
any_of(ValidReplacements,
4393+
any_of(Ops,
44014394
[=](const auto &Rep) { return impliesPoison(BO, Rep.first); }))
44024395
return Absorber;
44034396
}

llvm/test/Transforms/InstCombine/select.ll

Lines changed: 2 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -4831,11 +4831,8 @@ define i32 @replace_and_cond_multiuse2(i1 %cond1, i1 %cond2) {
48314831

48324832
define i32 @src_simplify_2x_at_once_and(i32 %x, i32 %y) {
48334833
; CHECK-LABEL: @src_simplify_2x_at_once_and(
4834-
; CHECK-NEXT: [[AND:%.*]] = and i32 [[X:%.*]], [[Y:%.*]]
4835-
; CHECK-NEXT: [[AND0:%.*]] = icmp eq i32 [[AND]], -1
4836-
; CHECK-NEXT: [[XOR:%.*]] = xor i32 [[X]], [[Y]]
4837-
; CHECK-NEXT: [[COND:%.*]] = select i1 [[AND0]], i32 0, i32 [[XOR]]
4838-
; CHECK-NEXT: ret i32 [[COND]]
4834+
; CHECK-NEXT: [[XOR:%.*]] = xor i32 [[X:%.*]], [[Y:%.*]]
4835+
; CHECK-NEXT: ret i32 [[XOR]]
48394836
;
48404837
%and = and i32 %x, %y
48414838
%and0 = icmp eq i32 %and, -1

0 commit comments

Comments
 (0)