[PATCH] D139289: [SCCP] Propagate equality of a not-constant
luxufan via Phabricator via llvm-commits
llvm-commits at lists.llvm.org
Mon Dec 5 03:54:43 PST 2022
This revision was landed with ongoing or failed builds.
This revision was automatically updated to reflect the committed changes.
Closed by commit rGb0f78769178e: [SCCP] Propagate equality of a not-constant (authored by StephenFan).
Repository:
rG LLVM Github Monorepo
CHANGES SINCE LAST ACTION
https://reviews.llvm.org/D139289/new/
https://reviews.llvm.org/D139289
Files:
llvm/lib/Transforms/Utils/SCCPSolver.cpp
llvm/test/Transforms/SCCP/conditions-ranges.ll
Index: llvm/test/Transforms/SCCP/conditions-ranges.ll
===================================================================
--- llvm/test/Transforms/SCCP/conditions-ranges.ll
+++ llvm/test/Transforms/SCCP/conditions-ranges.ll
@@ -1370,6 +1370,69 @@
ret void
}
+define i32 @equal_not_constant(ptr noundef %p, ptr noundef %q) {
+; CHECK-LABEL: @equal_not_constant(
+; CHECK-NEXT: entry:
+; CHECK-NEXT: [[CMP:%.*]] = icmp ne ptr [[P:%.*]], null
+; CHECK-NEXT: br i1 [[CMP]], label [[IF_THEN:%.*]], label [[IF_END:%.*]]
+; CHECK: if.then:
+; CHECK-NEXT: [[CMP_THEN:%.*]] = icmp eq ptr [[P]], [[Q:%.*]]
+; CHECK-NEXT: br i1 [[CMP_THEN]], label [[IF_THEN1:%.*]], label [[IF_END]]
+; CHECK: if.then1:
+; CHECK-NEXT: call void @use(i1 true)
+; CHECK-NEXT: br label [[IF_END]]
+; CHECK: if.end:
+; CHECK-NEXT: ret i32 0
+;
+entry:
+ %cmp = icmp ne ptr %p, null
+ br i1 %cmp, label %if.then, label %if.end
+
+if.then: ; preds = %entry
+ %cmp.then = icmp eq ptr %p, %q
+ br i1 %cmp.then, label %if.then1, label %if.end
+
+if.then1: ; preds = %if.then
+ %cmp.then1 = icmp ne ptr %q, null
+ call void @use(i1 %cmp.then1)
+ br label %if.end
+
+if.end:
+ ret i32 0
+}
+
+define i32 @not_equal_not_constant(ptr noundef %p, ptr noundef %q) {
+; CHECK-LABEL: @not_equal_not_constant(
+; CHECK-NEXT: entry:
+; CHECK-NEXT: [[CMP:%.*]] = icmp ne ptr [[P:%.*]], null
+; CHECK-NEXT: br i1 [[CMP]], label [[IF_THEN:%.*]], label [[IF_END:%.*]]
+; CHECK: if.then:
+; CHECK-NEXT: [[CMP_THEN:%.*]] = icmp ne ptr [[P]], [[Q:%.*]]
+; CHECK-NEXT: br i1 [[CMP_THEN]], label [[IF_THEN1:%.*]], label [[IF_END]]
+; CHECK: if.then1:
+; CHECK-NEXT: [[CMP_THEN1:%.*]] = icmp ne ptr [[Q]], null
+; CHECK-NEXT: call void @use(i1 [[CMP_THEN1]])
+; CHECK-NEXT: br label [[IF_END]]
+; CHECK: if.end:
+; CHECK-NEXT: ret i32 0
+;
+entry:
+ %cmp = icmp ne ptr %p, null
+ br i1 %cmp, label %if.then, label %if.end
+
+if.then: ; preds = %entry
+ %cmp.then = icmp ne ptr %p, %q
+ br i1 %cmp.then, label %if.then1, label %if.end
+
+if.then1: ; preds = %if.then
+ %cmp.then1 = icmp ne ptr %q, null
+ call void @use(i1 %cmp.then1)
+ br label %if.end
+
+if.end:
+ ret i32 0
+}
+
define i1 @ptr_icmp_data_layout() {
; CHECK-LABEL: @ptr_icmp_data_layout(
; CHECK-NEXT: ret i1 false
Index: llvm/lib/Transforms/Utils/SCCPSolver.cpp
===================================================================
--- llvm/lib/Transforms/Utils/SCCPSolver.cpp
+++ llvm/lib/Transforms/Utils/SCCPSolver.cpp
@@ -1344,9 +1344,10 @@
IV, &CB,
ValueLatticeElement::getRange(NewCR, /*MayIncludeUndef*/ false));
return;
- } else if (Pred == CmpInst::ICMP_EQ && CondVal.isConstant()) {
+ } else if (Pred == CmpInst::ICMP_EQ &&
+ (CondVal.isConstant() || CondVal.isNotConstant())) {
// For non-integer values or integer constant expressions, only
- // propagate equal constants.
+ // propagate equal constants or not-constants.
addAdditionalUser(OtherOp, &CB);
mergeInValue(IV, &CB, CondVal);
return;
-------------- next part --------------
A non-text attachment was scrubbed...
Name: D139289.480043.patch
Type: text/x-patch
Size: 3300 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/llvm-commits/attachments/20221205/ceff9800/attachment.bin>
More information about the llvm-commits
mailing list