[PATCH] D64869: [SCEV] get more accurate range for AddExpr with NW flag

Nikita Popov via Phabricator via llvm-commits llvm-commits at lists.llvm.org
Mon Dec 23 02:14:23 PST 2019


nikic accepted this revision.
nikic added a comment.
This revision is now accepted and ready to land.

LGTM



================
Comment at: llvm/test/Transforms/IRCE/ranges_of_different_types.ll:87
 ; CHECK-NEXT:      [[CMP2:%[^ ]+]] = icmp slt i32 [[SUB1]], 101
-; CHECK-NEXT:      [[SMAX2:%[^ ]+]] = select i1 [[CMP2]], i32 [[SUB1]], i32 101
-; CHECK-NEXT:      [[CMP3:%[^ ]+]] = icmp sgt i32 [[SMAX2]], 0
-; CHECK-NEXT:      %exit.mainloop.at = select i1 [[CMP3]], i32 [[SMAX2]], i32 0
+; CHECK-NEXT:      %exit.mainloop.at = select i1 [[CMP2]], i32 [[SUB1]], i32 101
 ; CHECK-NEXT:      br i1 true, label %loop.preloop.preheader
----------------
shchenz wrote:
> nikic wrote:
> > Can you get a range dump for this code? I'm not entirely clear on why we get an improvement here (assuming the metadata on the load is taken into account, I don't see where addWithNoWrap would produce a better result).
> Before the change, SCEV for `exit.mainloop.at` is `(0 smax (101 smin ((-1 * (-13 smax (-2147483647 + %len)<nuw><nsw>))<nsw> + %len)<nuw><nsw>))`, now we take `nuw` for add into account, so we get conclusion that `(101 smin ((-1 * (-13 smax (-2147483647 + %len)<nuw><nsw>))<nsw> + %len)<nuw><nsw>)` will not be smaller than 0. So after the change, SCEV for `exit.mainloop.at` is changed to ` (101 smin ((-1 * (-13 smax (-2147483647 + %len)<nuw><nsw>))<nsw> + %len)<nuw><nsw>)`
Thanks. So the difference comes from the `sub`, which is really a `add nuw nsw` on '-1 * %smax1`.


CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D64869/new/

https://reviews.llvm.org/D64869





More information about the llvm-commits mailing list