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

ChenZheng via Phabricator via llvm-commits llvm-commits at lists.llvm.org
Sun Dec 22 23:38:56 PST 2019


shchenz added inline comments.


================
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
----------------
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>)`


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

https://reviews.llvm.org/D64869





More information about the llvm-commits mailing list