Skip to content

Commit 5e81d67

Browse files
committed
[PPCBoolRetToInt] Avoid use of ConstantExpr::getZExt() (NFC)
Use IRBuilder instead, which will either insert an instruction or constant fold.
1 parent 23ef8bf commit 5e81d67

File tree

1 file changed

+9
-9
lines changed

1 file changed

+9
-9
lines changed

llvm/lib/Target/PowerPC/PPCBoolRetToInt.cpp

Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -45,6 +45,7 @@
4545
#include "llvm/IR/Instruction.h"
4646
#include "llvm/IR/Instructions.h"
4747
#include "llvm/IR/IntrinsicInst.h"
48+
#include "llvm/IR/IRBuilder.h"
4849
#include "llvm/IR/OperandTraits.h"
4950
#include "llvm/IR/Type.h"
5051
#include "llvm/IR/Use.h"
@@ -95,8 +96,6 @@ class PPCBoolRetToInt : public FunctionPass {
9596
Type *IntTy = ST->isPPC64() ? Type::getInt64Ty(V->getContext())
9697
: Type::getInt32Ty(V->getContext());
9798

98-
if (auto *C = dyn_cast<Constant>(V))
99-
return ConstantExpr::getZExt(C, IntTy);
10099
if (auto *P = dyn_cast<PHINode>(V)) {
101100
// Temporarily set the operands to 0. We'll fix this later in
102101
// runOnUse.
@@ -108,13 +107,12 @@ class PPCBoolRetToInt : public FunctionPass {
108107
return Q;
109108
}
110109

111-
auto *A = dyn_cast<Argument>(V);
112-
auto *I = dyn_cast<Instruction>(V);
113-
assert((A || I) && "Unknown value type");
114-
115-
auto InstPt =
116-
A ? &*A->getParent()->getEntryBlock().begin() : I->getNextNode();
117-
return new ZExtInst(V, IntTy, "", InstPt);
110+
IRBuilder IRB(V->getContext());
111+
if (auto *I = dyn_cast<Instruction>(V))
112+
IRB.SetInsertPoint(I->getNextNode());
113+
else
114+
IRB.SetInsertPoint(&Func->getEntryBlock(), Func->getEntryBlock().begin());
115+
return IRB.CreateZExt(V, IntTy);
118116
}
119117

120118
typedef SmallPtrSet<const PHINode *, 8> PHINodeSet;
@@ -196,6 +194,7 @@ class PPCBoolRetToInt : public FunctionPass {
196194

197195
auto &TM = TPC->getTM<PPCTargetMachine>();
198196
ST = TM.getSubtargetImpl(F);
197+
Func = &F;
199198

200199
PHINodeSet PromotablePHINodes = getPromotablePHINodes(F);
201200
B2IMap Bool2IntMap;
@@ -277,6 +276,7 @@ class PPCBoolRetToInt : public FunctionPass {
277276

278277
private:
279278
const PPCSubtarget *ST;
279+
Function *Func;
280280
};
281281

282282
} // end anonymous namespace

0 commit comments

Comments
 (0)