[llvm] [InstCombine] Invalidate changes to `DoesConsume` if the first try fails (PR #82973)
via llvm-commits
llvm-commits at lists.llvm.org
Mon Feb 26 09:30:43 PST 2024
================
@@ -0,0 +1,40 @@
+; NOTE: Assertions have been autogenerated by utils/update_test_checks.py UTC_ARGS: --version 4
+; RUN: opt -S -passes=instcombine < %s | FileCheck %s
+
+define i64 @func(i32 %p) {
+; CHECK-LABEL: define i64 @func(
+; CHECK-SAME: i32 [[P:%.*]]) {
+; CHECK-NEXT: entry:
+; CHECK-NEXT: [[NOT:%.*]] = xor i32 [[P]], -1
+; CHECK-NEXT: br label [[FOR_BODY:%.*]]
+; CHECK: for.body:
+; CHECK-NEXT: [[P0:%.*]] = phi i32 [ [[NOT]], [[ENTRY:%.*]] ], [ [[CONV:%.*]], [[FOR_BODY]] ]
+; CHECK-NEXT: [[P1:%.*]] = phi i32 [ 0, [[ENTRY]] ], [ [[INC:%.*]], [[FOR_BODY]] ]
+; CHECK-NEXT: [[INC]] = add i32 [[P1]], 1
+; CHECK-NEXT: [[CMP1_NOT:%.*]] = icmp eq i32 [[INC]], 0
+; CHECK-NEXT: [[COND:%.*]] = select i1 [[CMP1_NOT]], i32 -1231558963, i32 0
+; CHECK-NEXT: [[XOR:%.*]] = xor i32 [[COND]], [[P0]]
+; CHECK-NEXT: [[CMP2:%.*]] = icmp ne i32 [[XOR]], -2
+; CHECK-NEXT: [[CONV]] = zext i1 [[CMP2]] to i32
+; CHECK-NEXT: br i1 [[CMP2]], label [[FOR_BODY]], label [[FOR_EXIT:%.*]]
+; CHECK: for.exit:
+; CHECK-NEXT: ret i64 0
+;
+entry:
+ %not = xor i32 %p, -1
+ br label %for.body
+
+for.body:
+ %p0 = phi i32 [ %not, %entry ], [ %conv, %for.body ]
+ %p1 = phi i32 [ 0, %entry ], [ %inc, %for.body ]
+ %inc = add i32 %p1, 1
+ %cmp1 = icmp ne i32 %inc, 0
+ %cond = select i1 %cmp1, i32 0, i32 -1231558963
+ %xor = xor i32 %cond, %p0
+ %cmp2 = icmp ne i32 %xor, -2
+ %conv = zext i1 %cmp2 to i32
+ br i1 %cmp2, label %for.body, label %for.exit
+
+for.exit:
+ ret i64 0
+}
----------------
goldsteinn wrote:
Reduced test:
```
define i64 @func(i32 %p, i1 %cmp1) {
entry:
%not = xor i32 %p, -1
br label %for.body
for.body: ; preds = %for.body, %entry
%p0 = phi i32 [ %not, %entry ], [ %conv, %for.body ]
%cond = select i1 %cmp1, i32 0, i32 -1231558963
%xor = xor i32 %cond, %p0
%cmp2 = icmp ne i32 %xor, 1
%conv = zext i1 %cmp2 to i32
br label %for.body
}
```
https://github.com/llvm/llvm-project/pull/82973
More information about the llvm-commits
mailing list