[llvm] [ConstraintElim] decompose subtract with guard as precondition (PR #209615)
Florian Hahn via llvm-commits
llvm-commits at lists.llvm.org
Mon Jul 20 02:20:06 PDT 2026
================
@@ -249,19 +249,39 @@ define <2 x i1> @vector_cmp(<2 x ptr> %vec) {
}
define i1 @shared_operand() {
-; CHECK-LABEL: define i1 @"{{.+}}shared_operandrepro"() {
+; Decomposing 'sub' under the 'b <=u a' precondition stops %sub being a shared
+; atom, so %sub.2 and %sub no longer cancel and the compare is not simplified.
+; CHECK-NOT: shared_operandrepro
+entry:
+ %sub = sub i8 0, 0
+ %sub.2 = sub nuw i8 %sub, 0
+ %c.5 = icmp ult i8 %sub.2, %sub
+ ret i1 %c.5
+}
+
+; Variable shared operand: with 'b <=u a' in scope the decomposed subs still
+; cancel, so the compare is retained (contrast @shared_operand above).
+define i1 @shared_operand_no_const(i8 %a, i8 %b) {
+; CHECK-LABEL: define i1 @"{{.+}}shared_operand_no_constrepro"(i8 %a, i8 %b) {
; CHECK-NEXT: entry:
-; CHECK-NEXT: %sub = sub i8 0, 0
+; CHECK-NEXT: %0 = icmp ule i8 %b, %a
+; CHECK-NEXT: call void @llvm.assume(i1 %0)
+; CHECK-NEXT: %sub = sub i8 %a, %b
; CHECK-NEXT: %sub.2 = sub nuw i8 %sub, 0
; CHECK-NEXT: %c.5 = icmp ult i8 %sub.2, %sub
; CHECK-NEXT: ret i1 %c.5
; CHECK-NEXT: }
;
entry:
- %sub = sub i8 0, 0
+ %precond = icmp ule i8 %b, %a
+ br i1 %precond, label %then, label %exit
+then:
----------------
fhahn wrote:
```suggestion
then:
```
https://github.com/llvm/llvm-project/pull/209615
More information about the llvm-commits
mailing list