[llvm] [LVI] Thread binop over select with constant arms (PR #110212)

Nikita Popov via llvm-commits llvm-commits at lists.llvm.org
Sun Dec 8 13:38:15 PST 2024


================
@@ -630,3 +630,40 @@ define i64 @test_shl_nsw_at_use(i64 noundef %x) {
   %res = select i1 %cmp, i64 %shr, i64 0
   ret i64 %res
 }
+
+define i1 @test_icmp_mod(i64 noundef %x) {
+; CHECK-LABEL: @test_icmp_mod(
+; CHECK-NEXT:  entry:
+; CHECK-NEXT:    [[REM:%.*]] = srem i64 [[X:%.*]], 86400
+; CHECK-NEXT:    [[CMP:%.*]] = icmp slt i64 [[REM]], 0
+; CHECK-NEXT:    [[COND:%.*]] = select i1 [[CMP]], i64 86400, i64 0
+; CHECK-NEXT:    [[ADD:%.*]] = add nsw i64 [[COND]], [[REM]]
+; CHECK-NEXT:    ret i1 false
+;
+entry:
+  %rem = srem i64 %x, 86400
+  %cmp = icmp slt i64 %rem, 0
+  %cond = select i1 %cmp, i64 86400, i64 0
+  %add = add nsw i64 %cond, %rem
+  %cmp1 = icmp ugt i64 %add, 86399
----------------
nikic wrote:

Should also check that the computed range is actually correct, so add variants (or extra uses) that go one outside the boundary values.

https://github.com/llvm/llvm-project/pull/110212


More information about the llvm-commits mailing list