From bb1c44a3f975bf8fb72216b9c04bcd34e31bd815 Mon Sep 17 00:00:00 2001 From: Alon Zakai Date: Wed, 17 May 2017 11:29:11 -0700 Subject: optimize if and select in the case their values are identical (#1013) --- src/passes/OptimizeInstructions.cpp | 39 +++++++++++++++++++++++++++++++++++++ 1 file changed, 39 insertions(+) (limited to 'src') diff --git a/src/passes/OptimizeInstructions.cpp b/src/passes/OptimizeInstructions.cpp index c1787b57d..50a7c5589 100644 --- a/src/passes/OptimizeInstructions.cpp +++ b/src/passes/OptimizeInstructions.cpp @@ -596,6 +596,18 @@ struct OptimizeInstructions : public WalkerPassifTrue, iff->ifFalse); } } + if (ExpressionAnalyzer::equal(iff->ifTrue, iff->ifFalse)) { + // sides are identical, fold + if (!EffectAnalyzer(getPassOptions(), iff->condition).hasSideEffects()) { + return iff->ifTrue; + } else { + Builder builder(*getModule()); + return builder.makeSequence( + builder.makeDrop(iff->condition), + iff->ifTrue + ); + } + } } } else if (auto* select = curr->dynCast