[llvm] [GVN][NewGVN][Local] Handle attributes for function calls after CSE (PR #114011)
Yingwei Zheng via llvm-commits
llvm-commits at lists.llvm.org
Tue Oct 29 01:14:06 PDT 2024
================
@@ -0,0 +1,33 @@
+; NOTE: Assertions have been autogenerated by utils/update_test_checks.py UTC_ARGS: --version 5
+; RUN: opt -S -passes=gvn < %s | FileCheck %s
+
+; Make sure attributes in function calls are intersected correctly.
+
+define i1 @bucket(i32 noundef %x) {
+; CHECK-LABEL: define i1 @bucket(
+; CHECK-SAME: i32 noundef [[X:%.*]]) {
+; CHECK-NEXT: [[CMP1:%.*]] = icmp sgt i32 [[X]], 0
+; CHECK-NEXT: [[CTPOP1:%.*]] = tail call range(i32 0, 33) i32 @llvm.ctpop.i32(i32 [[X]])
+; CHECK-NEXT: [[CMP2:%.*]] = icmp samesign ult i32 [[CTPOP1]], 2
+; CHECK-NEXT: [[COND:%.*]] = select i1 [[CMP1]], i1 [[CMP2]], i1 false
+; CHECK-NEXT: br i1 [[COND]], label %[[IF_THEN:.*]], label %[[IF_ELSE:.*]]
+; CHECK: [[IF_ELSE]]:
+; CHECK-NEXT: [[RES:%.*]] = icmp eq i32 [[CTPOP1]], 1
+; CHECK-NEXT: ret i1 [[RES]]
+; CHECK: [[IF_THEN]]:
+; CHECK-NEXT: ret i1 false
+;
+ %cmp1 = icmp sgt i32 %x, 0
+ %ctpop1 = tail call range(i32 1, 32) i32 @llvm.ctpop.i32(i32 %x)
+ %cmp2 = icmp samesign ult i32 %ctpop1, 2
+ %cond = select i1 %cmp1, i1 %cmp2, i1 false
+ br i1 %cond, label %if.then, label %if.else
+
+if.else:
+ %ctpop2 = tail call range(i32 0, 33) i32 @llvm.ctpop.i32(i32 %x)
+ %res = icmp eq i32 %ctpop2, 1
+ ret i1 %res
+
+if.then:
+ ret i1 false
----------------
dtcxzyw wrote:
> what happen if there was a call to ctpop here also that can intersect with the entry block call but not with the if.else call?
In practice, it implies that the ctpop call in `%if.else` cannot intersect with the entry block call. Even if it happens, we do CSE first for calls in the entry and `%if.else`, and the second CSE will be rejected.
https://github.com/llvm/llvm-project/pull/114011
More information about the llvm-commits
mailing list