[llvm] r365259 - [IRBuilder] Introduce helpers for and/or of multiple values at once
Philip Reames via llvm-commits
llvm-commits at lists.llvm.org
Fri Jul 5 20:46:18 PDT 2019
Author: reames
Date: Fri Jul 5 20:46:18 2019
New Revision: 365259
URL: http://llvm.org/viewvc/llvm-project?rev=365259&view=rev
Log:
[IRBuilder] Introduce helpers for and/or of multiple values at once
We had versions of this code scattered around, so consolidate into one location.
Not strictly NFC since the order of intermediate results may change in some places, but since these operations are associatives, should not change results.
Modified:
llvm/trunk/include/llvm/IR/IRBuilder.h
llvm/trunk/lib/Transforms/Instrumentation/MemorySanitizer.cpp
llvm/trunk/lib/Transforms/Scalar/LoopPredication.cpp
llvm/trunk/lib/Transforms/Scalar/SimpleLoopUnswitch.cpp
Modified: llvm/trunk/include/llvm/IR/IRBuilder.h
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/include/llvm/IR/IRBuilder.h?rev=365259&r1=365258&r2=365259&view=diff
==============================================================================
--- llvm/trunk/include/llvm/IR/IRBuilder.h (original)
+++ llvm/trunk/include/llvm/IR/IRBuilder.h Fri Jul 5 20:46:18 2019
@@ -1214,6 +1214,14 @@ public:
return CreateAnd(LHS, ConstantInt::get(LHS->getType(), RHS), Name);
}
+ Value *CreateAnd(ArrayRef<Value*> Ops) {
+ assert(!Ops.empty());
+ Value *Accum = Ops[0];
+ for (unsigned i = 1; i < Ops.size(); i++)
+ Accum = CreateAnd(Accum, Ops[i]);
+ return Accum;
+ }
+
Value *CreateOr(Value *LHS, Value *RHS, const Twine &Name = "") {
if (auto *RC = dyn_cast<Constant>(RHS)) {
if (RC->isNullValue())
@@ -1232,6 +1240,14 @@ public:
return CreateOr(LHS, ConstantInt::get(LHS->getType(), RHS), Name);
}
+ Value *CreateOr(ArrayRef<Value*> Ops) {
+ assert(!Ops.empty());
+ Value *Accum = Ops[0];
+ for (unsigned i = 1; i < Ops.size(); i++)
+ Accum = CreateOr(Accum, Ops[i]);
+ return Accum;
+ }
+
Value *CreateXor(Value *LHS, Value *RHS, const Twine &Name = "") {
if (Value *V = foldConstant(Instruction::Xor, LHS, RHS, Name)) return V;
return Insert(BinaryOperator::CreateXor(LHS, RHS), Name);
Modified: llvm/trunk/lib/Transforms/Instrumentation/MemorySanitizer.cpp
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/lib/Transforms/Instrumentation/MemorySanitizer.cpp?rev=365259&r1=365258&r2=365259&view=diff
==============================================================================
--- llvm/trunk/lib/Transforms/Instrumentation/MemorySanitizer.cpp (original)
+++ llvm/trunk/lib/Transforms/Instrumentation/MemorySanitizer.cpp Fri Jul 5 20:46:18 2019
@@ -1943,7 +1943,7 @@ struct MemorySanitizerVisitor : public I
Value *S1S2 = IRB.CreateAnd(S1, S2);
Value *V1S2 = IRB.CreateAnd(V1, S2);
Value *S1V2 = IRB.CreateAnd(S1, V2);
- setShadow(&I, IRB.CreateOr(S1S2, IRB.CreateOr(V1S2, S1V2)));
+ setShadow(&I, IRB.CreateOr({S1S2, V1S2, S1V2}));
setOriginForNaryOp(I);
}
@@ -1965,7 +1965,7 @@ struct MemorySanitizerVisitor : public I
Value *S1S2 = IRB.CreateAnd(S1, S2);
Value *V1S2 = IRB.CreateAnd(V1, S2);
Value *S1V2 = IRB.CreateAnd(S1, V2);
- setShadow(&I, IRB.CreateOr(S1S2, IRB.CreateOr(V1S2, S1V2)));
+ setShadow(&I, IRB.CreateOr({S1S2, V1S2, S1V2}));
setOriginForNaryOp(I);
}
@@ -3508,7 +3508,7 @@ struct MemorySanitizerVisitor : public I
D = CreateAppToShadowCast(IRB, D);
// Result shadow if condition shadow is 1.
- Sa1 = IRB.CreateOr(IRB.CreateXor(C, D), IRB.CreateOr(Sc, Sd));
+ Sa1 = IRB.CreateOr({IRB.CreateXor(C, D), Sc, Sd});
}
Value *Sa = IRB.CreateSelect(Sb, Sa1, Sa0, "_msprop_select");
setShadow(&I, Sa);
Modified: llvm/trunk/lib/Transforms/Scalar/LoopPredication.cpp
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/lib/Transforms/Scalar/LoopPredication.cpp?rev=365259&r1=365258&r2=365259&view=diff
==============================================================================
--- llvm/trunk/lib/Transforms/Scalar/LoopPredication.cpp (original)
+++ llvm/trunk/lib/Transforms/Scalar/LoopPredication.cpp Fri Jul 5 20:46:18 2019
@@ -793,14 +793,9 @@ bool LoopPredication::widenGuardConditio
// Emit the new guard condition
IRBuilder<> Builder(findInsertPt(Guard, Checks));
- Value *LastCheck = nullptr;
- for (auto *Check : Checks)
- if (!LastCheck)
- LastCheck = Check;
- else
- LastCheck = Builder.CreateAnd(LastCheck, Check);
+ Value *AllChecks = Builder.CreateAnd(Checks);
auto *OldCond = Guard->getOperand(0);
- Guard->setOperand(0, LastCheck);
+ Guard->setOperand(0, AllChecks);
RecursivelyDeleteTriviallyDeadInstructions(OldCond);
LLVM_DEBUG(dbgs() << "Widened checks = " << NumWidened << "\n");
@@ -824,14 +819,9 @@ bool LoopPredication::widenWidenableBran
// Emit the new guard condition
IRBuilder<> Builder(findInsertPt(BI, Checks));
- Value *LastCheck = nullptr;
- for (auto *Check : Checks)
- if (!LastCheck)
- LastCheck = Check;
- else
- LastCheck = Builder.CreateAnd(LastCheck, Check);
+ Value *AllChecks = Builder.CreateAnd(Checks);
auto *OldCond = BI->getCondition();
- BI->setCondition(LastCheck);
+ BI->setCondition(AllChecks);
assert(isGuardAsWidenableBranch(BI) &&
"Stopped being a guard after transform?");
RecursivelyDeleteTriviallyDeadInstructions(OldCond);
Modified: llvm/trunk/lib/Transforms/Scalar/SimpleLoopUnswitch.cpp
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/lib/Transforms/Scalar/SimpleLoopUnswitch.cpp?rev=365259&r1=365258&r2=365259&view=diff
==============================================================================
--- llvm/trunk/lib/Transforms/Scalar/SimpleLoopUnswitch.cpp (original)
+++ llvm/trunk/lib/Transforms/Scalar/SimpleLoopUnswitch.cpp Fri Jul 5 20:46:18 2019
@@ -180,14 +180,9 @@ static void buildPartialUnswitchConditio
BasicBlock &UnswitchedSucc,
BasicBlock &NormalSucc) {
IRBuilder<> IRB(&BB);
- Value *Cond = Invariants.front();
- for (Value *Invariant :
- make_range(std::next(Invariants.begin()), Invariants.end()))
- if (Direction)
- Cond = IRB.CreateOr(Cond, Invariant);
- else
- Cond = IRB.CreateAnd(Cond, Invariant);
-
+
+ Value *Cond = Direction ? IRB.CreateOr(Invariants) :
+ IRB.CreateAnd(Invariants);
IRB.CreateCondBr(Cond, Direction ? &UnswitchedSucc : &NormalSucc,
Direction ? &NormalSucc : &UnswitchedSucc);
}
More information about the llvm-commits
mailing list