summaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
Diffstat (limited to 'src')
-rw-r--r--src/passes/OptimizeInstructions.cpp20
1 files changed, 20 insertions, 0 deletions
diff --git a/src/passes/OptimizeInstructions.cpp b/src/passes/OptimizeInstructions.cpp
index 293adcbde..6a66ae603 100644
--- a/src/passes/OptimizeInstructions.cpp
+++ b/src/passes/OptimizeInstructions.cpp
@@ -756,6 +756,26 @@ struct OptimizeInstructions : public WalkerPass<PostWalker<OptimizeInstructions,
std::swap(select->ifTrue, select->ifFalse);
}
}
+ if (auto* c = select->condition->dynCast<Const>()) {
+ // constant condition, we can just pick the right side (barring side effects)
+ if (c->value.getInteger()) {
+ if (!EffectAnalyzer(getPassOptions(), select->ifFalse).hasSideEffects()) {
+ return select->ifTrue;
+ } else {
+ // don't bother - we would need to reverse the order using a temp local, which is bad
+ }
+ } else {
+ if (!EffectAnalyzer(getPassOptions(), select->ifTrue).hasSideEffects()) {
+ return select->ifFalse;
+ } else {
+ Builder builder(*getModule());
+ return builder.makeSequence(
+ builder.makeDrop(select->ifTrue),
+ select->ifFalse
+ );
+ }
+ }
+ }
if (ExpressionAnalyzer::equal(select->ifTrue, select->ifFalse)) {
// sides are identical, fold
EffectAnalyzer value(getPassOptions(), select->ifTrue);