[PATCH] D102367: [LowerConstantIntrinsics] only accept ConstantData other than UndefValue as constant
Nick Desaulniers via Phabricator via llvm-commits
llvm-commits at lists.llvm.org
Wed May 12 15:51:41 PDT 2021
nickdesaulniers updated this revision to Diff 344977.
nickdesaulniers added a comment.
- add tests for undef, fix check all DFS
Repository:
rG LLVM Github Monorepo
CHANGES SINCE LAST ACTION
https://reviews.llvm.org/D102367/new/
https://reviews.llvm.org/D102367
Files:
llvm/lib/Transforms/Scalar/LowerConstantIntrinsics.cpp
llvm/test/Transforms/LowerConstantIntrinsics/constant-intrinsics.ll
Index: llvm/test/Transforms/LowerConstantIntrinsics/constant-intrinsics.ll
===================================================================
--- llvm/test/Transforms/LowerConstantIntrinsics/constant-intrinsics.ll
+++ llvm/test/Transforms/LowerConstantIntrinsics/constant-intrinsics.ll
@@ -112,3 +112,26 @@
ret i1 %res6
}
+
+ at real_mode_blob_end = external dso_local global [0 x i8], align 1
+define i1 @global_array() {
+; CHECK-LABEL: @global_array(
+; CHECK-NEXT: ret i1 false
+ %1 = call i1 @llvm.is.constant.i64(i64 ptrtoint ([0 x i8]* @real_mode_blob_end to i64))
+ ret i1 %1
+}
+
+define i1 @undef1() {
+; CHECK-LABEL: undef1(
+; CHECK-NEXT: ret i1 false
+ %1 = call i1 @llvm.is.constant.i64(i64 undef)
+ ret i1 %1
+}
+
+ at undef_array = dso_local global [2 x i8] [i8 42, i8 undef]
+define i1 @undef2() {
+; CHECK-LABEL: undef2(
+; CHECK-NEXT: ret i1 false
+ %1 = call i1 @llvm.is.constant.i64(i64 ptrtoint ([2 x i8]* @undef_array to i64))
+ ret i1 %1
+}
Index: llvm/lib/Transforms/Scalar/LowerConstantIntrinsics.cpp
===================================================================
--- llvm/lib/Transforms/Scalar/LowerConstantIntrinsics.cpp
+++ llvm/lib/Transforms/Scalar/LowerConstantIntrinsics.cpp
@@ -45,10 +45,18 @@
"Number of 'objectsize' intrinsic calls handled");
static Value *lowerIsConstantIntrinsic(IntrinsicInst *II) {
- Value *Op = II->getOperand(0);
-
- return isa<Constant>(Op) ? ConstantInt::getTrue(II->getType())
- : ConstantInt::getFalse(II->getType());
+ SmallVector<Value *> WorkList;
+ WorkList.push_back(II->getOperand(0));
+ while (WorkList.size()) {
+ Value *V = WorkList.back();
+ if (!isa<ConstantData>(V) || isa<UndefValue>(V))
+ return ConstantInt::getFalse(II->getType());
+ WorkList.pop_back();
+ if (auto *CA = dyn_cast<ConstantAggregate>(V))
+ for (Value *Op : CA->operands())
+ WorkList.push_back(Op);
+ }
+ return ConstantInt::getTrue(II->getType());
}
static bool replaceConditionalBranchesOnConstant(Instruction *II,
-------------- next part --------------
A non-text attachment was scrubbed...
Name: D102367.344977.patch
Type: text/x-patch
Size: 2054 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/llvm-commits/attachments/20210512/4cbdf912/attachment.bin>
More information about the llvm-commits
mailing list