[PATCH] D153718: [SCCP] Don't always set MayIncludeUndef as true when calling markConstant
luxufan via Phabricator via llvm-commits
llvm-commits at lists.llvm.org
Sun Jun 25 08:26:35 PDT 2023
StephenFan created this revision.
StephenFan added a reviewer: nikic.
Herald added a subscriber: hiraditya.
Herald added a project: All.
StephenFan requested review of this revision.
Herald added a project: LLVM.
Herald added a subscriber: llvm-commits.
In markConstant, MayIncludeUndef makes a difference when the Constant is
ConstantInt. Currently we hard code MayIncludeUndef as true, but in fact
only when there is at least one operand has
constantrange_including_undef, the simplifed result can
MayIncludingUndef.
Repository:
rG LLVM Github Monorepo
https://reviews.llvm.org/D153718
Files:
llvm/lib/Transforms/Utils/SCCPSolver.cpp
llvm/test/Transforms/SCCP/ip-ranges-phis.ll
Index: llvm/test/Transforms/SCCP/ip-ranges-phis.ll
===================================================================
--- llvm/test/Transforms/SCCP/ip-ranges-phis.ll
+++ llvm/test/Transforms/SCCP/ip-ranges-phis.ll
@@ -56,11 +56,11 @@
; CHECK-NEXT: [[V_2:%.*]] = select i1 [[C_2]], i32 20, i32 200
; CHECK-NEXT: [[V_3:%.*]] = select i1 [[C_3]], i32 30, i32 300
; CHECK-NEXT: [[R_1:%.*]] = add nuw nsw i32 [[V_1]], [[V_2]]
-; CHECK-NEXT: [[R_2:%.*]] = add i32 [[R_1]], [[V_3]]
-; CHECK-NEXT: [[R_3:%.*]] = add i32 [[R_2]], 400
-; CHECK-NEXT: [[R_4:%.*]] = add i32 [[R_3]], 50
-; CHECK-NEXT: [[R_5:%.*]] = add i32 [[R_4]], 60
-; CHECK-NEXT: [[R_6:%.*]] = add i32 [[R_4]], 700
+; CHECK-NEXT: [[R_2:%.*]] = add nuw nsw i32 [[R_1]], [[V_3]]
+; CHECK-NEXT: [[R_3:%.*]] = add nuw nsw i32 [[R_2]], 400
+; CHECK-NEXT: [[R_4:%.*]] = add nuw nsw i32 [[R_3]], 50
+; CHECK-NEXT: [[R_5:%.*]] = add nuw nsw i32 [[R_4]], 60
+; CHECK-NEXT: [[R_6:%.*]] = add nuw nsw i32 [[R_4]], 700
; CHECK-NEXT: ret i32 [[R_6]]
;
@@ -111,7 +111,7 @@
; CHECK-NEXT: [[P1:%.*]] = phi i32 [ 0, [[ENTRY:%.*]] ], [ 1, [[IF_TRUE]] ]
; CHECK-NEXT: [[P2:%.*]] = phi i32 [ 1, [[ENTRY]] ], [ -10, [[IF_TRUE]] ]
; CHECK-NEXT: [[P3:%.*]] = phi i32 [ 1, [[ENTRY]] ], [ 10, [[IF_TRUE]] ]
-; CHECK-NEXT: [[CALL1:%.*]] = tail call i32 @f2(i32 [[P1]], i32 [[P2]], i32 [[P3]], i1 [[CMP_1]], i1 [[CMP_2]])
+; CHECK-NEXT: [[CALL1:%.*]] = tail call i32 @f2(i32 [[P1]], i32 [[P2]], i32 [[P3]], i1 [[CMP_1]], i1 [[CMP_2]]), !range [[RNG0:![0-9]+]]
; CHECK-NEXT: ret i32 [[CALL1]]
;
@@ -204,7 +204,7 @@
; CHECK-NEXT: br label [[END]]
; CHECK: end:
; CHECK-NEXT: [[P1:%.*]] = phi i32 [ 0, [[ENTRY:%.*]] ], [ 5, [[IF_TRUE]] ]
-; CHECK-NEXT: [[CALL1:%.*]] = tail call i32 @f3(i32 [[P1]], i32 [[Y]], i1 [[CMP_1]]), !range [[RNG0:![0-9]+]]
+; CHECK-NEXT: [[CALL1:%.*]] = tail call i32 @f3(i32 [[P1]], i32 [[Y]], i1 [[CMP_1]]), !range [[RNG1:![0-9]+]]
; CHECK-NEXT: ret i32 [[CALL1]]
;
Index: llvm/lib/Transforms/Utils/SCCPSolver.cpp
===================================================================
--- llvm/lib/Transforms/Utils/SCCPSolver.cpp
+++ llvm/lib/Transforms/Utils/SCCPSolver.cpp
@@ -1450,7 +1450,8 @@
// after one of the operands go to overdefined, e.g. due to one operand
// being a special floating value.
ValueLatticeElement NewV;
- NewV.markConstant(C, /*MayIncludeUndef=*/true);
+ NewV.markConstant(C, V1State.isConstantRangeIncludingUndef() ||
+ V2State.isConstantRangeIncludingUndef());
return (void)mergeInValue(&I, NewV);
}
}
-------------- next part --------------
A non-text attachment was scrubbed...
Name: D153718.534315.patch
Type: text/x-patch
Size: 2663 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/llvm-commits/attachments/20230625/8fde06da/attachment-0001.bin>
More information about the llvm-commits
mailing list