[PATCH] D24700: [InstCombine] optimize unsigned icmp of inc/dec like signed

Matti Niemenmaa via llvm-commits llvm-commits at lists.llvm.org
Sat Sep 17 08:14:00 PDT 2016


Deewiant created this revision.
Deewiant added reviewers: majnemer, spatel.
Deewiant added a subscriber: llvm-commits.

Allows LLVM to optimize sequences like the following:

```
%add = add nuw i32 %x, 1
%cmp = icmp ugt i32 %add, %y
```

Into:

```
%cmp = icmp uge i32 %x, %y
```

Previously, only signed comparisons were being handled.

Note that `add nuw %x, -1` is poison if `%x` is nonzero so we could be more aggressive for those cases. I think that it would be more useful to instead match `sub nuw %x, 1` here, which is poison only when `%x` is zero, but InstCombineAddSub currently canonicalizes that to `add %x, -1` losing the `nuw` flag. Changing that behaviour seems like it might have far-reaching ramifications so I kept this simple.

https://reviews.llvm.org/D24700

Files:
  lib/Transforms/InstCombine/InstCombineCompares.cpp
  test/Transforms/InstCombine/icmp.ll

-------------- next part --------------
A non-text attachment was scrubbed...
Name: D24700.71733.patch
Type: text/x-patch
Size: 4213 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/llvm-commits/attachments/20160917/66085be8/attachment.bin>


More information about the llvm-commits mailing list