Skip to content

Commit 0c03f48

Browse files
committed
Revert "InstSimplify: Require instruction be parented"
This reverts commit 1536e29. Causes large binary size regressions, see comments on https://reviews.llvm.org/rG1536e299e63d7788f38117b0212ca50eb76d7a3b.
1 parent 935c8b6 commit 0c03f48

File tree

17 files changed

+72
-53
lines changed

17 files changed

+72
-53
lines changed

llvm/docs/ReleaseNotes.rst

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -77,9 +77,6 @@ Changes to LLVM infrastructure
7777
legacy inliner pass. Backend stack coloring should handle cases alloca
7878
merging initially set out to handle.
7979

80-
* InstructionSimplify APIs now require instructions be inserted into a
81-
parent function.
82-
8380
Changes to building LLVM
8481
------------------------
8582

llvm/include/llvm/Analysis/InstructionSimplify.h

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -19,8 +19,12 @@
1919
// values. This will prevent other code from seeing the same undef uses and
2020
// resolving them to different values.
2121
//
22-
// They require that all the IR that they encounter be valid and inserted into a
23-
// parent function.
22+
// These routines are designed to tolerate moderately incomplete IR, such as
23+
// instructions that are not connected to basic blocks yet. However, they do
24+
// require that all the IR that they encounter be valid. In particular, they
25+
// require that all non-constant values be defined in the same function, and the
26+
// same call context of that function (and not split between caller and callee
27+
// contexts of a directly recursive call, for example).
2428
//
2529
// Additionally, these routines can't simplify to the instructions that are not
2630
// def-reachable, meaning we can't just scan the basic block for instructions

llvm/include/llvm/IR/BasicBlock.h

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -251,10 +251,7 @@ class BasicBlock final : public Value, // Basic blocks are data objects also
251251

252252
/// Unlink this basic block from its current function and insert it into
253253
/// the function that \p MovePos lives in, right before \p MovePos.
254-
inline void moveBefore(BasicBlock *MovePos) {
255-
moveBefore(MovePos->getIterator());
256-
}
257-
void moveBefore(SymbolTableList<BasicBlock>::iterator MovePos);
254+
void moveBefore(BasicBlock *MovePos);
258255

259256
/// Unlink this basic block from its current function and insert it
260257
/// right after \p MovePos in the function \p MovePos lives in.

llvm/lib/Analysis/InstructionSimplify.cpp

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6749,7 +6749,6 @@ static Value *simplifyInstructionWithOperands(Instruction *I,
67496749
ArrayRef<Value *> NewOps,
67506750
const SimplifyQuery &SQ,
67516751
unsigned MaxRecurse) {
6752-
assert(I->getFunction() && "instruction should be inserted in a function");
67536752
const SimplifyQuery Q = SQ.CxtI ? SQ : SQ.getWithInstruction(I);
67546753

67556754
switch (I->getOpcode()) {

llvm/lib/IR/BasicBlock.cpp

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -133,8 +133,9 @@ iplist<BasicBlock>::iterator BasicBlock::eraseFromParent() {
133133
return getParent()->getBasicBlockList().erase(getIterator());
134134
}
135135

136-
void BasicBlock::moveBefore(SymbolTableList<BasicBlock>::iterator MovePos) {
137-
getParent()->splice(MovePos, getParent(), getIterator());
136+
void BasicBlock::moveBefore(BasicBlock *MovePos) {
137+
MovePos->getParent()->splice(MovePos->getIterator(), getParent(),
138+
getIterator());
138139
}
139140

140141
void BasicBlock::moveAfter(BasicBlock *MovePos) {

llvm/lib/Transforms/Scalar/JumpThreading.cpp

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2643,7 +2643,6 @@ bool JumpThreadingPass::duplicateCondBranchOnPHIIntoPred(
26432643
// mapping and using it to remap operands in the cloned instructions.
26442644
for (; BI != BB->end(); ++BI) {
26452645
Instruction *New = BI->clone();
2646-
New->insertInto(PredBB, OldPredBranch->getIterator());
26472646

26482647
// Remap operands to patch up intra-block references.
26492648
for (unsigned i = 0, e = New->getNumOperands(); i != e; ++i)
@@ -2661,7 +2660,7 @@ bool JumpThreadingPass::duplicateCondBranchOnPHIIntoPred(
26612660
{BB->getModule()->getDataLayout(), TLI, nullptr, nullptr, New})) {
26622661
ValueMapping[&*BI] = IV;
26632662
if (!New->mayHaveSideEffects()) {
2664-
New->eraseFromParent();
2663+
New->deleteValue();
26652664
New = nullptr;
26662665
}
26672666
} else {
@@ -2670,6 +2669,7 @@ bool JumpThreadingPass::duplicateCondBranchOnPHIIntoPred(
26702669
if (New) {
26712670
// Otherwise, insert the new instruction into the block.
26722671
New->setName(BI->getName());
2672+
New->insertInto(PredBB, OldPredBranch->getIterator());
26732673
// Update Dominance from simplified New instruction operands.
26742674
for (unsigned i = 0, e = New->getNumOperands(); i != e; ++i)
26752675
if (BasicBlock *SuccBB = dyn_cast<BasicBlock>(New->getOperand(i)))

llvm/lib/Transforms/Utils/CloneFunction.cpp

Lines changed: 9 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -470,8 +470,9 @@ void PruningFunctionCloner::CloneBlock(
470470

471471
// Nope, clone it now.
472472
BasicBlock *NewBB;
473-
Twine NewName(BB->hasName() ? Twine(BB->getName()) + NameSuffix : "");
474-
BBEntry = NewBB = BasicBlock::Create(BB->getContext(), NewName, NewFunc);
473+
BBEntry = NewBB = BasicBlock::Create(BB->getContext());
474+
if (BB->hasName())
475+
NewBB->setName(BB->getName() + NameSuffix);
475476

476477
// It is only legal to clone a function if a block address within that
477478
// function is never referenced outside of the function. Given that, we
@@ -497,7 +498,6 @@ void PruningFunctionCloner::CloneBlock(
497498
++II) {
498499

499500
Instruction *NewInst = cloneInstruction(II);
500-
NewInst->insertInto(NewBB, NewBB->end());
501501

502502
if (HostFuncIsStrictFP) {
503503
// All function calls in the inlined function must get 'strictfp'
@@ -516,6 +516,8 @@ void PruningFunctionCloner::CloneBlock(
516516
// If we can simplify this instruction to some other value, simply add
517517
// a mapping to that value rather than inserting a new instruction into
518518
// the basic block.
519+
//
520+
// FIXME: simplifyInstruction should know the context of the new function.
519521
if (Value *V =
520522
simplifyInstruction(NewInst, BB->getModule()->getDataLayout())) {
521523
// On the off-chance that this simplifies to an instruction in the old
@@ -526,7 +528,7 @@ void PruningFunctionCloner::CloneBlock(
526528

527529
if (!NewInst->mayHaveSideEffects()) {
528530
VMap[&*II] = V;
529-
NewInst->eraseFromParent();
531+
NewInst->deleteValue();
530532
continue;
531533
}
532534
}
@@ -535,6 +537,7 @@ void PruningFunctionCloner::CloneBlock(
535537
if (II->hasName())
536538
NewInst->setName(II->getName() + NameSuffix);
537539
VMap[&*II] = NewInst; // Add instruction map to value.
540+
NewInst->insertInto(NewBB, NewBB->end());
538541
if (isa<CallInst>(II) && !II->isDebugOrPseudoInst()) {
539542
hasCalls = true;
540543
hasMemProfMetadata |= II->hasMetadata(LLVMContext::MD_memprof);
@@ -682,8 +685,8 @@ void llvm::CloneAndPruneIntoFromInst(Function *NewFunc, const Function *OldFunc,
682685
if (!NewBB)
683686
continue; // Dead block.
684687

685-
// Move the new block to preserve the order in the original function.
686-
NewBB->moveBefore(NewFunc->end());
688+
// Add the new block to the new function.
689+
NewFunc->insert(NewFunc->end(), NewBB);
687690

688691
// Handle PHI nodes specially, as we have to remove references to dead
689692
// blocks.

llvm/lib/Transforms/Utils/LoopRotationUtils.cpp

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -435,8 +435,6 @@ bool LoopRotate::rotateLoop(Loop *L, bool SimplifiedLatch) {
435435

436436
// Otherwise, create a duplicate of the instruction.
437437
Instruction *C = Inst->clone();
438-
C->insertBefore(LoopEntryBranch);
439-
440438
++NumInstrsDuplicated;
441439

442440
// Eagerly remap the operands of the instruction.
@@ -446,7 +444,7 @@ bool LoopRotate::rotateLoop(Loop *L, bool SimplifiedLatch) {
446444
// Avoid inserting the same intrinsic twice.
447445
if (auto *DII = dyn_cast<DbgVariableIntrinsic>(C))
448446
if (DbgIntrinsics.count(makeHash(DII))) {
449-
C->eraseFromParent();
447+
C->deleteValue();
450448
continue;
451449
}
452450

@@ -459,7 +457,7 @@ bool LoopRotate::rotateLoop(Loop *L, bool SimplifiedLatch) {
459457
// in the map.
460458
InsertNewValueIntoMap(ValueMap, Inst, V);
461459
if (!C->mayHaveSideEffects()) {
462-
C->eraseFromParent();
460+
C->deleteValue();
463461
C = nullptr;
464462
}
465463
} else {
@@ -468,6 +466,7 @@ bool LoopRotate::rotateLoop(Loop *L, bool SimplifiedLatch) {
468466
if (C) {
469467
// Otherwise, stick the new instruction into the new block!
470468
C->setName(Inst->getName());
469+
C->insertBefore(LoopEntryBranch);
471470

472471
if (auto *II = dyn_cast<AssumeInst>(C))
473472
AC->registerAssumption(II);

llvm/lib/Transforms/Utils/SimplifyCFG.cpp

Lines changed: 4 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -3211,9 +3211,6 @@ FoldCondBranchOnValueKnownInPredecessorImpl(BranchInst *BI, DomTreeUpdater *DTU,
32113211
}
32123212
// Clone the instruction.
32133213
Instruction *N = BBI->clone();
3214-
// Insert the new instruction into its new home.
3215-
N->insertInto(EdgeBB, InsertPt);
3216-
32173214
if (BBI->hasName())
32183215
N->setName(BBI->getName() + ".c");
32193216

@@ -3229,15 +3226,17 @@ FoldCondBranchOnValueKnownInPredecessorImpl(BranchInst *BI, DomTreeUpdater *DTU,
32293226
if (!BBI->use_empty())
32303227
TranslateMap[&*BBI] = V;
32313228
if (!N->mayHaveSideEffects()) {
3232-
N->eraseFromParent(); // Instruction folded away, don't need actual
3233-
// inst
3229+
N->deleteValue(); // Instruction folded away, don't need actual inst
32343230
N = nullptr;
32353231
}
32363232
} else {
32373233
if (!BBI->use_empty())
32383234
TranslateMap[&*BBI] = N;
32393235
}
32403236
if (N) {
3237+
// Insert the new instruction into its new home.
3238+
N->insertInto(EdgeBB, InsertPt);
3239+
32413240
// Register the new instruction with the assumption cache if necessary.
32423241
if (auto *Assume = dyn_cast<AssumeInst>(N))
32433242
if (AC)

llvm/test/Transforms/Inline/inline_inv_group.ll

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -14,9 +14,8 @@ define ptr @callee() alwaysinline {
1414
ret ptr %1
1515
}
1616

17-
define ptr @caller() null_pointer_is_valid {
18-
; CHECK-LABEL: define ptr @caller
19-
; CHECK-SAME: () #[[ATTR1:[0-9]+]] {
17+
define ptr @caller() {
18+
; CHECK-LABEL: define ptr @caller() {
2019
; CHECK-NEXT: [[TMP1:%.*]] = call ptr @llvm.strip.invariant.group.p0(ptr null)
2120
; CHECK-NEXT: ret ptr [[TMP1]]
2221
;

llvm/test/Transforms/Inline/simplify-instruction-computeKnownFPClass-context.ll

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,8 @@ define i1 @simplify_fcmp_ord_fdiv_caller(double nofpclass(zero nan inf) %i0, dou
3030
; CHECK-LABEL: define i1 @simplify_fcmp_ord_fdiv_caller
3131
; CHECK-SAME: (double nofpclass(nan inf zero) [[I0:%.*]], double nofpclass(nan inf zero) [[I1:%.*]]) {
3232
; CHECK-NEXT: [[SUB_DOUBLE_SUB_I:%.*]] = fdiv double [[I0]], [[I1]]
33-
; CHECK-NEXT: ret i1 true
33+
; CHECK-NEXT: [[CMP_I:%.*]] = fcmp ord double [[SUB_DOUBLE_SUB_I]], 0.000000e+00
34+
; CHECK-NEXT: ret i1 [[CMP_I]]
3435
;
3536
%call = call i1 @simplify_fcmp_ord_fdiv_callee(double %i0, double %i1)
3637
ret i1 %call
@@ -47,7 +48,8 @@ define i1 @simplify_fcmp_ord_frem_caller(double nofpclass(zero nan inf) %i0, dou
4748
; CHECK-LABEL: define i1 @simplify_fcmp_ord_frem_caller
4849
; CHECK-SAME: (double nofpclass(nan inf zero) [[I0:%.*]], double nofpclass(nan inf zero) [[I1:%.*]]) {
4950
; CHECK-NEXT: [[SUB_DOUBLE_SUB_I:%.*]] = frem double [[I0]], [[I1]]
50-
; CHECK-NEXT: ret i1 true
51+
; CHECK-NEXT: [[CMP_I:%.*]] = fcmp ord double [[SUB_DOUBLE_SUB_I]], 0.000000e+00
52+
; CHECK-NEXT: ret i1 [[CMP_I]]
5153
;
5254
%call = call i1 @simplify_fcmp_ord_frem_callee(double %i0, double %i1)
5355
ret i1 %call
@@ -64,7 +66,8 @@ define i1 @simplify_fcmp_ord_fmul_caller(double nofpclass(zero nan) %i0, double
6466
; CHECK-LABEL: define i1 @simplify_fcmp_ord_fmul_caller
6567
; CHECK-SAME: (double nofpclass(nan zero) [[I0:%.*]], double nofpclass(nan zero) [[I1:%.*]]) {
6668
; CHECK-NEXT: [[SUB_DOUBLE_SUB_I:%.*]] = fmul double [[I0]], [[I1]]
67-
; CHECK-NEXT: ret i1 true
69+
; CHECK-NEXT: [[CMP_I:%.*]] = fcmp ord double [[SUB_DOUBLE_SUB_I]], 0.000000e+00
70+
; CHECK-NEXT: ret i1 [[CMP_I]]
6871
;
6972
%call = call i1 @simplify_fcmp_ord_fmul_callee(double %i0, double %i1)
7073
ret i1 %call

llvm/test/Transforms/LoopRotate/pr56260.ll

Lines changed: 7 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -14,17 +14,18 @@ define void @main() {
1414
; CHECK: L0.preheader:
1515
; CHECK-NEXT: [[CMP:%.*]] = icmp slt i32 0, 0
1616
; CHECK-NEXT: [[INC:%.*]] = zext i1 [[CMP]] to i32
17-
; CHECK-NEXT: [[TOBOOL3_NOT1:%.*]] = icmp eq i32 [[INC]], 0
18-
; CHECK-NEXT: br i1 [[TOBOOL3_NOT1]], label [[L0_PREHEADER_LOOPEXIT]], label [[L1_PREHEADER_LR_PH:%.*]]
17+
; CHECK-NEXT: [[SPEC_SELECT1:%.*]] = add nsw i32 0, [[INC]]
18+
; CHECK-NEXT: [[TOBOOL3_NOT2:%.*]] = icmp eq i32 [[SPEC_SELECT1]], 0
19+
; CHECK-NEXT: br i1 [[TOBOOL3_NOT2]], label [[L0_PREHEADER_LOOPEXIT]], label [[L1_PREHEADER_LR_PH:%.*]]
1920
; CHECK: L1.preheader.lr.ph:
2021
; CHECK-NEXT: br label [[L1_PREHEADER:%.*]]
2122
; CHECK: L1.preheader:
22-
; CHECK-NEXT: [[SPEC_SELECT3:%.*]] = phi i32 [ [[INC]], [[L1_PREHEADER_LR_PH]] ], [ [[SPEC_SELECT:%.*]], [[L0_LATCH:%.*]] ]
23-
; CHECK-NEXT: [[K_02:%.*]] = phi i32 [ 0, [[L1_PREHEADER_LR_PH]] ], [ [[SPEC_SELECT3]], [[L0_LATCH]] ]
24-
; CHECK-NEXT: [[TOBOOL8_NOT:%.*]] = icmp eq i32 [[K_02]], 0
23+
; CHECK-NEXT: [[SPEC_SELECT4:%.*]] = phi i32 [ [[SPEC_SELECT1]], [[L1_PREHEADER_LR_PH]] ], [ [[SPEC_SELECT:%.*]], [[L0_LATCH:%.*]] ]
24+
; CHECK-NEXT: [[K_03:%.*]] = phi i32 [ 0, [[L1_PREHEADER_LR_PH]] ], [ [[SPEC_SELECT4]], [[L0_LATCH]] ]
25+
; CHECK-NEXT: [[TOBOOL8_NOT:%.*]] = icmp eq i32 [[K_03]], 0
2526
; CHECK-NEXT: br label [[L0_LATCH]]
2627
; CHECK: L0.latch:
27-
; CHECK-NEXT: [[SPEC_SELECT]] = add nsw i32 [[SPEC_SELECT3]], [[INC]]
28+
; CHECK-NEXT: [[SPEC_SELECT]] = add nsw i32 [[SPEC_SELECT4]], [[INC]]
2829
; CHECK-NEXT: [[TOBOOL3_NOT:%.*]] = icmp eq i32 [[SPEC_SELECT]], 0
2930
; CHECK-NEXT: br i1 [[TOBOOL3_NOT]], label [[L0_L0_PREHEADER_LOOPEXIT_CRIT_EDGE:%.*]], label [[L1_PREHEADER]]
3031
;

llvm/test/Transforms/PhaseOrdering/runtime-check-removal.ll

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -10,20 +10,20 @@ define void @test_remove_check_with_incrementing_integer_induction(i16 %start, i
1010
; CHECK-LABEL: @test_remove_check_with_incrementing_integer_induction(
1111
; CHECK-NEXT: entry:
1212
; CHECK-NEXT: [[LEN:%.*]] = zext i8 [[LEN_N:%.*]] to i16
13-
; CHECK-NEXT: [[LEN_NEG_NOT:%.*]] = icmp ult i16 [[LEN]], [[A:%.*]]
14-
; CHECK-NEXT: [[C1:%.*]] = icmp ne i8 [[LEN_N]], 0
15-
; CHECK-NEXT: [[OR_COND3:%.*]] = and i1 [[LEN_NEG_NOT]], [[C1]]
16-
; CHECK-NEXT: br i1 [[OR_COND3]], label [[LOOP_LATCH_PREHEADER:%.*]], label [[EXIT:%.*]]
13+
; CHECK-NEXT: [[LEN_NEG_NOT:%.*]] = icmp uge i16 [[LEN]], [[A:%.*]]
14+
; CHECK-NEXT: [[C1_NOT:%.*]] = icmp eq i8 [[LEN_N]], 0
15+
; CHECK-NEXT: [[OR_COND:%.*]] = or i1 [[LEN_NEG_NOT]], [[C1_NOT]]
16+
; CHECK-NEXT: br i1 [[OR_COND]], label [[EXIT:%.*]], label [[LOOP_LATCH_PREHEADER:%.*]]
1717
; CHECK: loop.latch.preheader:
1818
; CHECK-NEXT: [[TMP0:%.*]] = add i16 [[A]], -1
1919
; CHECK-NEXT: [[TMP1:%.*]] = add nsw i16 [[LEN]], -1
2020
; CHECK-NEXT: [[UMIN:%.*]] = tail call i16 @llvm.umin.i16(i16 [[TMP0]], i16 [[TMP1]])
2121
; CHECK-NEXT: br label [[LOOP_LATCH:%.*]]
2222
; CHECK: loop.latch:
23-
; CHECK-NEXT: [[IV2:%.*]] = phi i16 [ [[IV_NEXT:%.*]], [[LOOP_LATCH]] ], [ 0, [[LOOP_LATCH_PREHEADER]] ]
24-
; CHECK-NEXT: tail call void @use(i16 [[IV2]])
25-
; CHECK-NEXT: [[IV_NEXT]] = add nuw nsw i16 [[IV2]], 1
26-
; CHECK-NEXT: [[EXITCOND_NOT:%.*]] = icmp eq i16 [[IV2]], [[UMIN]]
23+
; CHECK-NEXT: [[IV4:%.*]] = phi i16 [ [[IV_NEXT:%.*]], [[LOOP_LATCH]] ], [ 0, [[LOOP_LATCH_PREHEADER]] ]
24+
; CHECK-NEXT: tail call void @use(i16 [[IV4]])
25+
; CHECK-NEXT: [[IV_NEXT]] = add nuw nsw i16 [[IV4]], 1
26+
; CHECK-NEXT: [[EXITCOND_NOT:%.*]] = icmp eq i16 [[IV4]], [[UMIN]]
2727
; CHECK-NEXT: br i1 [[EXITCOND_NOT]], label [[EXIT]], label [[LOOP_LATCH]]
2828
; CHECK: exit:
2929
; CHECK-NEXT: ret void

llvm/test/Transforms/SampleProfile/profile-context-tracker-debug.ll

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,7 @@
2727
; INLINE-ALL-NEXT: Getting callee context for instr: %call.i = tail call i32 @_Z8funcLeafi
2828
; INLINE-ALL-NEXT: Callee context found: main:3 @ _Z5funcAi:1 @ _Z8funcLeafi
2929
; INLINE-ALL-NEXT: Marking context profile as inlined: main:3 @ _Z5funcAi:1 @ _Z8funcLeafi
30-
; INLINE-ALL-NEXT: Getting callee context for instr: %call.i2 = tail call i32 @_Z3fibi
30+
; INLINE-ALL-NEXT: Getting callee context for instr: %call.i1 = tail call i32 @_Z3fibi
3131
; INLINE-ALL-NEXT: Getting callee context for instr: %call5.i = tail call i32 @_Z3fibi
3232
; INLINE-ALL-DAG: Getting base profile for function: _Z5funcAi
3333
; INLINE-ALL-DAG-NEXT: Merging context profile into base profile: _Z5funcAi

llvm/test/Transforms/SampleProfile/pseudo-probe-stale-profile-matching.ll

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -80,9 +80,9 @@
8080
; CHECK: 5: call void @llvm.pseudoprobe(i64 -2624081020897602054, i64 5, i32 0, i64 -1), !dbg ![[#]] - weight: 0 - factor: 1.00)
8181
; CHECK: 1: call void @llvm.pseudoprobe(i64 6699318081062747564, i64 1, i32 0, i64 -1), !dbg ![[#]] - weight: 112 - factor: 1.00)
8282
; CHECK: 2: call void @llvm.pseudoprobe(i64 6699318081062747564, i64 2, i32 0, i64 -1), !dbg ![[#]] - weight: 101 - factor: 1.00)
83-
; CHECK: 5: %call.i8 = call i32 @bar(i32 noundef %1), !dbg ![[#]] - weight: 101 - factor: 1.00)
83+
; CHECK: 5: %call.i3 = call i32 @bar(i32 noundef %1), !dbg ![[#]] - weight: 101 - factor: 1.00)
8484
; CHECK: 3: call void @llvm.pseudoprobe(i64 6699318081062747564, i64 3, i32 0, i64 -1), !dbg ![[#]] - weight: 13 - factor: 1.00)
85-
; CHECK: 6: %call1.i5 = call i32 @bar(i32 noundef %add.i4), !dbg ![[#]] - weight: 13 - factor: 1.00)
85+
; CHECK: 6: %call1.i6 = call i32 @bar(i32 noundef %add.i5), !dbg ![[#]] - weight: 13 - factor: 1.00)
8686
; CHECK: 4: call void @llvm.pseudoprobe(i64 6699318081062747564, i64 4, i32 0, i64 -1), !dbg ![[#]] - weight: 112 - factor: 1.00)
8787
; CHECK: 14: %call2 = call i32 @bar(i32 noundef %3), !dbg ![[#]] - weight: 124 - factor: 1.00)
8888
; CHECK: 8: call void @llvm.pseudoprobe(i64 -2624081020897602054, i64 8, i32 0, i64 -1), !dbg ![[#]] - weight: 0 - factor: 1.00)

llvm/test/Transforms/SimplifyCFG/pr46638.ll

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,9 @@ define void @pr46638(i1 %c, i32 %x) {
1515
; CHECK: common.ret:
1616
; CHECK-NEXT: ret void
1717
; CHECK: true2.critedge:
18-
; CHECK-NEXT: call void @dummy(i32 0)
18+
; CHECK-NEXT: [[CMP2_C:%.*]] = icmp sgt i32 [[X]], 0
19+
; CHECK-NEXT: [[EXT_C:%.*]] = zext i1 [[CMP2_C]] to i32
20+
; CHECK-NEXT: call void @dummy(i32 [[EXT_C]])
1921
; CHECK-NEXT: call void @dummy(i32 2)
2022
; CHECK-NEXT: br label [[COMMON_RET]]
2123
;

llvm/unittests/Transforms/Utils/LocalTest.cpp

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -588,6 +588,21 @@ TEST_F(SalvageDebugInfoTest, RecursiveBlockSimplification) {
588588
verifyDebugValuesAreSalvaged();
589589
}
590590

591+
TEST(Local, SimplifyVScaleWithRange) {
592+
LLVMContext C;
593+
Module M("Module", C);
594+
595+
IntegerType *Ty = Type::getInt32Ty(C);
596+
Function *VScale = Intrinsic::getDeclaration(&M, Intrinsic::vscale, {Ty});
597+
auto *CI = CallInst::Create(VScale, {}, "vscale");
598+
599+
// Test that simplifyCall won't try to query it's parent function for
600+
// vscale_range attributes in order to simplify llvm.vscale -> constant.
601+
EXPECT_EQ(simplifyCall(CI, VScale, {}, SimplifyQuery(M.getDataLayout())),
602+
nullptr);
603+
delete CI;
604+
}
605+
591606
TEST(Local, wouldInstructionBeTriviallyDead) {
592607
LLVMContext Ctx;
593608
std::unique_ptr<Module> M = parseIR(Ctx,

0 commit comments

Comments
 (0)