This patch handles signed icmp cases of Add and Sub based on D101778 if it guarantees no overflow after hoisting. For example:
https://alive2.llvm.org/ce/z/wbCO7s
define i32 @src(i32 %0) { %x = icmp sge i32 %0, 0 br i1 %x, label %nonnegative, label %5 nonnegative: ; preds = %1 %2 = icmp slt i32 %0, 13 br i1 %2, label %5, label %3 3: ; preds = %nonnegative %4 = add i32 %0, -13 ret i32 %4 5: ; preds = %nonnegative, %1 ret i32 0 } define i32 @tgt(i32 %0) { %x = icmp sge i32 %0, 0 br i1 %x, label %nonnegative, label %5 nonnegative: ; preds = %1 %2 = add i32 %0, -13 %3 = icmp slt i32 %2, 0 br i1 %3, label %5, label %4 4: ; preds = %nonnegative ret i32 %2 5: ; preds = %nonnegative, %1 ret i32 0 }
This patch addresses performance regressions in RISC-V benchmarks reported by our CI. I think this patch can protect against regressions from patch D147568.