[PATCH] D81246: [SCEV] ScalarEvolution::createSCEV(): Instruction::Or: drop completely bogus no-wrap flag detection

Roman Lebedev via Phabricator via llvm-commits llvm-commits at lists.llvm.org
Fri Jun 5 02:42:40 PDT 2020


lebedev.ri created this revision.
lebedev.ri added reviewers: mkazantsev, reames, sanjoy.
lebedev.ri added a project: LLVM.
Herald added a subscriber: hiraditya.

That's just really wrong. I don't see why it makes sense at all.

Good thing is, it wasn't miscompiling anything, because as long as
the operands of `or` had no common bits set, then the `add`
of these operands will never overflow: http://volta.cs.utah.edu:8080/z/gmt7Sy
IOW we need no detection, we are free to just set NUW+NSW.

But as rG39e3683534c83573da5c8b70c8adfb43948f601f <https://reviews.llvm.org/rG39e3683534c83573da5c8b70c8adfb43948f601f> shows,
even when the old code failed to "deduce" flags,
we'd eventually re-deduce them somewhere, later.

So let's just set them.


Repository:
  rG LLVM Github Monorepo

https://reviews.llvm.org/D81246

Files:
  llvm/lib/Analysis/ScalarEvolution.cpp


Index: llvm/lib/Analysis/ScalarEvolution.cpp
===================================================================
--- llvm/lib/Analysis/ScalarEvolution.cpp
+++ llvm/lib/Analysis/ScalarEvolution.cpp
@@ -6389,15 +6389,8 @@
         if (GetMinTrailingZeros(LHS) >=
             (CIVal.getBitWidth() - CIVal.countLeadingZeros())) {
           // Build a plain add SCEV.
-          const SCEV *S = getAddExpr(LHS, getSCEV(CI));
-          // If the LHS of the add was an addrec and it has no-wrap flags,
-          // transfer the no-wrap flags, since an or won't introduce a wrap.
-          if (const SCEVAddRecExpr *NewAR = dyn_cast<SCEVAddRecExpr>(S)) {
-            const SCEVAddRecExpr *OldAR = cast<SCEVAddRecExpr>(LHS);
-            const_cast<SCEVAddRecExpr *>(NewAR)->setNoWrapFlags(
-                OldAR->getNoWrapFlags());
-          }
-          return S;
+          return getAddExpr(LHS, getSCEV(CI),
+                            (SCEV::NoWrapFlags)(SCEV::FlagNUW | SCEV::FlagNSW));
         }
       }
       break;


-------------- next part --------------
A non-text attachment was scrubbed...
Name: D81246.268716.patch
Type: text/x-patch
Size: 1028 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/llvm-commits/attachments/20200605/79a62130/attachment.bin>


More information about the llvm-commits mailing list