[PATCH] D104932: [instcombine] Fold overflow check using overflow intrinsic to comparison

Philip Reames via Phabricator via llvm-commits llvm-commits at lists.llvm.org
Wed Jun 30 11:17:20 PDT 2021


reames added inline comments.


================
Comment at: llvm/test/Transforms/InstCombine/smulo.ll:38
 ; CHECK-LABEL: @test_constant2(
-; CHECK-NEXT:    [[RES:%.*]] = tail call { i8, i1 } @llvm.smul.with.overflow.i8(i8 [[A:%.*]], i8 2)
-; CHECK-NEXT:    [[OVERFLOW:%.*]] = extractvalue { i8, i1 } [[RES]], 1
+; CHECK-NEXT:    [[TMP1:%.*]] = add i8 [[A:%.*]], 64
+; CHECK-NEXT:    [[OVERFLOW:%.*]] = icmp slt i8 [[TMP1]], 0
----------------
There might be another lurking fold here, but I'm not quite seeing it.

This is basically implementing a lookup table for the top two bits with the original mapping being:
00 = false
01 = true
10 = true
11 = false

We could use a shift and popct here, but that's slower.  Any tricks you can think of for this formulation?

One the later cases is also a region lookup test, but with 8 regions not 4.



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

https://reviews.llvm.org/D104932



More information about the llvm-commits mailing list