Skip to content

Commit 3f067dc

Browse files
committed
apply comment
1 parent 968f346 commit 3f067dc

File tree

1 file changed

+12
-9
lines changed

1 file changed

+12
-9
lines changed

llvm/lib/Transforms/Vectorize/SLPVectorizer.cpp

Lines changed: 12 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -824,23 +824,25 @@ namespace {
824824
/// - Get the operands for the interchangeable form (getOperand)
825825
class InterchangeableInstruction {
826826
protected:
827-
Instruction *const MainOp;
827+
Instruction *const MainOp = nullptr;
828828

829829
public:
830830
InterchangeableInstruction(Instruction *MainOp) : MainOp(MainOp) {}
831831
virtual bool isSame(Instruction *I) {
832832
return MainOp->getOpcode() == I->getOpcode();
833833
}
834-
virtual unsigned getOpcode() { return MainOp->getOpcode(); }
835-
virtual SmallVector<Value *> getOperand(Instruction *I) {
836-
assert(MainOp->getOpcode() == I->getOpcode());
834+
virtual unsigned getOpcode() const { return MainOp->getOpcode(); }
835+
virtual SmallVector<Value *> getOperand(Instruction *I) const {
836+
assert(MainOp->getOpcode() == I->getOpcode() &&
837+
"Cannot convert the instruction.");
837838
return SmallVector<Value *>(MainOp->operands());
838839
}
839840
virtual ~InterchangeableInstruction() = default;
840841
};
841842

842843
class InterchangeableBinOp final : public InterchangeableInstruction {
843844
using MaskType = std::uint_fast8_t;
845+
// Sort SupportedOp because it is used by binary_search.
844846
constexpr static std::initializer_list<unsigned> SupportedOp = {
845847
Instruction::Add, Instruction::Sub, Instruction::Mul, Instruction::Shl,
846848
Instruction::AShr, Instruction::And, Instruction::Or, Instruction::Xor};
@@ -934,7 +936,7 @@ class InterchangeableBinOp final : public InterchangeableInstruction {
934936
}
935937
return tryAnd(opcodeToMask(Opcode));
936938
}
937-
unsigned getOpcode() override {
939+
unsigned getOpcode() const override {
938940
MaskType Candidate = Mask & SeenBefore;
939941
if (Candidate & 0b1)
940942
return Instruction::Shl;
@@ -954,7 +956,7 @@ class InterchangeableBinOp final : public InterchangeableInstruction {
954956
return Instruction::Xor;
955957
llvm_unreachable("Cannot find interchangeable instruction.");
956958
}
957-
SmallVector<Value *> getOperand(Instruction *I) override {
959+
SmallVector<Value *> getOperand(Instruction *I) const override {
958960
unsigned ToOpcode = I->getOpcode();
959961
assert(binary_search(SupportedOp, ToOpcode) && "Unsupported opcode.");
960962
unsigned FromOpcode = MainOp->getOpcode();
@@ -997,8 +999,9 @@ class InterchangeableBinOp final : public InterchangeableInstruction {
997999
ToCIValue = APInt::getZero(FromCIValueBitWidth);
9981000
break;
9991001
}
1000-
auto LHS = MainOp->getOperand(1 - Pos);
1001-
auto RHS = ConstantInt::get(MainOp->getOperand(Pos)->getType(), ToCIValue);
1002+
Value *LHS = MainOp->getOperand(1 - Pos);
1003+
Constant *RHS =
1004+
ConstantInt::get(MainOp->getOperand(Pos)->getType(), ToCIValue);
10021005
if (Pos == 1)
10031006
return SmallVector<Value *>({LHS, RHS});
10041007
return SmallVector<Value *>({RHS, LHS});
@@ -1363,7 +1366,7 @@ static InstructionsState getSameOpcode(ArrayRef<Value *> VL,
13631366
for (Value *V : VL) {
13641367
if (isa<PoisonValue>(V))
13651368
continue;
1366-
Instruction *Inst = cast<Instruction>(V);
1369+
auto *Inst = cast<Instruction>(V);
13671370
if (Inst->getOpcode() == InterchangeableInstructionOpcode)
13681371
return Inst;
13691372
}

0 commit comments

Comments
 (0)