[PATCH] D94089: [Reassociate] move check to ignore boolean expressions before canonicalizing binary operands

Marius Hillenbrand via Phabricator via llvm-commits llvm-commits at lists.llvm.org
Tue Jan 5 08:00:53 PST 2021


mhillenbrand created this revision.
mhillenbrand added reviewers: spatel, lebedev.ri.
Herald added a subscriber: hiraditya.
mhillenbrand requested review of this revision.
Herald added a project: LLVM.
Herald added a subscriber: llvm-commits.

The Reassociate pass intends to leave alone boolean (i1) expressions
to preserve the order of short-circuited comparisons, which SimplifyCFG
has folded into AND/OR expressions. The check to achieve that behavior
currently is ineffective since it only happens after
canonicalizeOperands() may already have flipped the order of operands
(and, consequentially, the order of short-circuited comparisons after
CodeGen). Move that check up to happen before the call to
canonicalizeOperands().

Bug: https://bugs.llvm.org/show_bug.cgi?id=48529


Repository:
  rG LLVM Github Monorepo

https://reviews.llvm.org/D94089

Files:
  llvm/lib/Transforms/Scalar/Reassociate.cpp


Index: llvm/lib/Transforms/Scalar/Reassociate.cpp
===================================================================
--- llvm/lib/Transforms/Scalar/Reassociate.cpp
+++ llvm/lib/Transforms/Scalar/Reassociate.cpp
@@ -2187,6 +2187,15 @@
       I = NI;
     }
 
+  // Do not reassociate boolean (i1) expressions.  We want to preserve the
+  // original order of evaluation for short-circuited comparisons that
+  // SimplifyCFG has folded to AND/OR expressions.  If the expression
+  // is not further optimized, it is likely to be transformed back to a
+  // short-circuited form for code gen, and the source order may have been
+  // optimized for the most likely conditions.
+  if (I->getType()->isIntegerTy(1))
+    return;
+
   // Commute binary operators, to canonicalize the order of their operands.
   // This can potentially expose more CSE opportunities, and makes writing other
   // transformations simpler.
@@ -2201,14 +2210,6 @@
   if (I->getType()->isFPOrFPVectorTy() && !I->isFast())
     return;
 
-  // Do not reassociate boolean (i1) expressions.  We want to preserve the
-  // original order of evaluation for short-circuited comparisons that
-  // SimplifyCFG has folded to AND/OR expressions.  If the expression
-  // is not further optimized, it is likely to be transformed back to a
-  // short-circuited form for code gen, and the source order may have been
-  // optimized for the most likely conditions.
-  if (I->getType()->isIntegerTy(1))
-    return;
 
   // If this is a bitwise or instruction of operands
   // with no common bits set, convert it to X+Y.


-------------- next part --------------
A non-text attachment was scrubbed...
Name: D94089.314616.patch
Type: text/x-patch
Size: 1584 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/llvm-commits/attachments/20210105/4214a0f7/attachment-0001.bin>


More information about the llvm-commits mailing list