Skip to content

Commit fcf2d5f

Browse files
committed
Revert "SROA: Enhance speculateSelectInstLoads"
This reverts commit ffc3fb6.
1 parent b5e470a commit fcf2d5f

File tree

3 files changed

+17
-66
lines changed

3 files changed

+17
-66
lines changed

llvm/lib/Transforms/Scalar/SROA.cpp

Lines changed: 3 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -1330,21 +1330,14 @@ static void speculatePHINodeLoads(PHINode &PN) {
13301330
/// %V = select i1 %cond, i32 %V1, i32 %V2
13311331
///
13321332
/// We can do this to a select if its only uses are loads and if the operand
1333-
/// to the select can be loaded unconditionally. If found an intervening bitcast
1334-
/// with a single use of the load, allow the promotion.
1333+
/// to the select can be loaded unconditionally.
13351334
static bool isSafeSelectToSpeculate(SelectInst &SI) {
13361335
Value *TValue = SI.getTrueValue();
13371336
Value *FValue = SI.getFalseValue();
13381337
const DataLayout &DL = SI.getModule()->getDataLayout();
13391338

13401339
for (User *U : SI.users()) {
1341-
LoadInst *LI;
1342-
BitCastInst *BC = dyn_cast<BitCastInst>(U);
1343-
if (BC && BC->hasOneUse())
1344-
LI = dyn_cast<LoadInst>(*BC->user_begin());
1345-
else
1346-
LI = dyn_cast<LoadInst>(U);
1347-
1340+
LoadInst *LI = dyn_cast<LoadInst>(U);
13481341
if (!LI || !LI->isSimple())
13491342
return false;
13501343

@@ -1370,24 +1363,10 @@ static void speculateSelectInstLoads(SelectInst &SI) {
13701363
Value *FV = SI.getFalseValue();
13711364
// Replace the loads of the select with a select of two loads.
13721365
while (!SI.use_empty()) {
1373-
LoadInst *LI;
1374-
BitCastInst *BC = dyn_cast<BitCastInst>(SI.user_back());
1375-
if (BC) {
1376-
assert(BC->hasOneUse() && "Bitcast should have a single use.");
1377-
LI = cast<LoadInst>(BC->user_back());
1378-
} else {
1379-
LI = cast<LoadInst>(SI.user_back());
1380-
}
1381-
1366+
LoadInst *LI = cast<LoadInst>(SI.user_back());
13821367
assert(LI->isSimple() && "We only speculate simple loads");
13831368

13841369
IRB.SetInsertPoint(LI);
1385-
if (BC) {
1386-
// Cast the operands to bitcast's target type.
1387-
TV = IRB.CreateBitCast(TV, BC->getType(), TV->getName() + ".sroa.cast");
1388-
FV = IRB.CreateBitCast(FV, BC->getType(), FV->getName() + ".sroa.cast");
1389-
}
1390-
13911370
LoadInst *TL = IRB.CreateLoad(LI->getType(), TV,
13921371
LI->getName() + ".sroa.speculate.load.true");
13931372
LoadInst *FL = IRB.CreateLoad(LI->getType(), FV,
@@ -1411,8 +1390,6 @@ static void speculateSelectInstLoads(SelectInst &SI) {
14111390
LLVM_DEBUG(dbgs() << " speculated to: " << *V << "\n");
14121391
LI->replaceAllUsesWith(V);
14131392
LI->eraseFromParent();
1414-
if (BC)
1415-
BC->eraseFromParent();
14161393
}
14171394
SI.eraseFromParent();
14181395
}

llvm/test/Transforms/SROA/phi-and-select.ll

Lines changed: 14 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -60,14 +60,23 @@ entry:
6060
ret i32 %result
6161
}
6262

63+
; If bitcast isn't considered a safe phi/select use, the alloca
64+
; remains as an array.
65+
; FIXME: Why isn't this identical to test2?
6366
define float @test2_bitcast() {
6467
; CHECK-LABEL: @test2_bitcast(
6568
; CHECK-NEXT: entry:
66-
; CHECK-NEXT: [[COND:%.*]] = icmp sle i32 0, 1
67-
; CHECK-NEXT: [[TMP0:%.*]] = bitcast i32 1 to float
68-
; CHECK-NEXT: [[TMP1:%.*]] = bitcast i32 0 to float
69-
; CHECK-NEXT: [[RESULT_SROA_SPECULATED:%.*]] = select i1 [[COND]], float [[TMP0]], float [[TMP1]]
70-
; CHECK-NEXT: ret float [[RESULT_SROA_SPECULATED]]
69+
; CHECK-NEXT: [[A_SROA_0:%.*]] = alloca i32, align 4
70+
; CHECK-NEXT: [[A_SROA_3:%.*]] = alloca i32, align 4
71+
; CHECK-NEXT: store i32 0, i32* [[A_SROA_0]], align 4
72+
; CHECK-NEXT: store i32 1, i32* [[A_SROA_3]], align 4
73+
; CHECK-NEXT: [[A_SROA_0_0_A_SROA_0_0_V0:%.*]] = load i32, i32* [[A_SROA_0]], align 4
74+
; CHECK-NEXT: [[A_SROA_3_0_A_SROA_3_4_V1:%.*]] = load i32, i32* [[A_SROA_3]], align 4
75+
; CHECK-NEXT: [[COND:%.*]] = icmp sle i32 [[A_SROA_0_0_A_SROA_0_0_V0]], [[A_SROA_3_0_A_SROA_3_4_V1]]
76+
; CHECK-NEXT: [[SELECT:%.*]] = select i1 [[COND]], i32* [[A_SROA_3]], i32* [[A_SROA_0]]
77+
; CHECK-NEXT: [[SELECT_BC:%.*]] = bitcast i32* [[SELECT]] to float*
78+
; CHECK-NEXT: [[RESULT:%.*]] = load float, float* [[SELECT_BC]], align 4
79+
; CHECK-NEXT: ret float [[RESULT]]
7180
;
7281
entry:
7382
%a = alloca [2 x i32]

llvm/test/Transforms/SROA/select-load.ll

Lines changed: 0 additions & 35 deletions
This file was deleted.

0 commit comments

Comments
 (0)