[PATCH] D75799: Don't create PHI nodes with "is.constant" values
Bill Wendling via Phabricator via llvm-commits
llvm-commits at lists.llvm.org
Sat Mar 7 03:15:14 PST 2020
void updated this revision to Diff 248920.
void added a comment.
Use pattern matching for intrinsic instruction matching.
Repository:
rG LLVM Github Monorepo
CHANGES SINCE LAST ACTION
https://reviews.llvm.org/D75799/new/
https://reviews.llvm.org/D75799
Files:
llvm/lib/Transforms/Scalar/JumpThreading.cpp
llvm/test/Transforms/JumpThreading/is_constant.ll
Index: llvm/test/Transforms/JumpThreading/is_constant.ll
===================================================================
--- /dev/null
+++ llvm/test/Transforms/JumpThreading/is_constant.ll
@@ -0,0 +1,39 @@
+; RUN: opt -jump-threading -S -verify < %s | FileCheck %s
+
+; CHECK-LABEL: define void @test1(
+; CHECK-LABEL: if.end18:
+; CHECK-NOT: call i1 @llvm.is.constant.i64
+define void @test1() {
+entry:
+ %conv = trunc i64 undef to i32
+ %conv8 = ashr exact i64 undef, 32
+ %cmp9 = icmp ugt i64 %conv8, 24
+ br i1 %cmp9, label %if.then11, label %if.end18
+
+if.then11: ; preds = %entry
+ br label %if.end18
+
+if.end18: ; preds = %if.then11, %entry
+ %len.0 = phi i32 [ 24, %if.then11 ], [ %conv, %entry ]
+ %cmp3.i.i70 = icmp ugt i32 %len.0, 24
+ %0 = call i1 @llvm.is.constant.i64(i64 undef) #1
+ br i1 %cmp3.i.i70, label %if.then.i.i71, label %if.end12.i.i74
+
+if.then.i.i71: ; preds = %if.end18
+ unreachable
+
+if.end12.i.i74: ; preds = %if.end18
+ br i1 %0, label %if.else.i.i, label %if.then7.i.i
+
+if.then7.i.i: ; preds = %if.end12.i.i74
+ ret void
+
+if.else.i.i: ; preds = %if.end12.i.i74
+ unreachable
+}
+
+; Function Attrs: nounwind readnone willreturn
+declare i1 @llvm.is.constant.i64(i64) #0
+
+attributes #0 = { nounwind readnone willreturn }
+attributes #1 = { nounwind }
Index: llvm/lib/Transforms/Scalar/JumpThreading.cpp
===================================================================
--- llvm/lib/Transforms/Scalar/JumpThreading.cpp
+++ llvm/lib/Transforms/Scalar/JumpThreading.cpp
@@ -2003,6 +2003,39 @@
void JumpThreadingPass::UpdateSSA(
BasicBlock *BB, BasicBlock *NewBB,
DenseMap<Instruction *, Value *> &ValueMapping) {
+ // Don't create PHI nodes with values from is_constant intrinsics. Code gated
+ // by these intrinsics sometimes rely upon their evaluation to DCE invalid
+ // paths. Combining them into PHI nodes complicates the evaluation.
+ SmallVector<Instruction *, 2> IsConstantIntrs;
+ for (Instruction &I : *BB) {
+ using namespace PatternMatch;
+ if (match(&I, m_Intrinsic<Intrinsic::is_constant>()))
+ continue;
+
+ // Scan all uses of this instruction to see if it is used outside of its
+ // block.
+ for (Use &U : I.uses()) {
+ Instruction *User = cast<Instruction>(U.getUser());
+ if (PHINode *UserPN = dyn_cast<PHINode>(User)) {
+ if (UserPN->getIncomingBlock(U) == BB)
+ continue;
+ } else if (User->getParent() == BB) {
+ continue;
+ }
+
+ IsConstantIntrs.push_back(&I);
+ break;
+ }
+ }
+
+ for (auto *II : IsConstantIntrs) {
+ Constant *Res = isa<Constant>(II->getOperand(0))
+ ? ConstantInt::getTrue(II->getType())
+ : ConstantInt::getFalse(II->getType());
+ II->replaceAllUsesWith(Res);
+ II->eraseFromParent();
+ }
+
// If there were values defined in BB that are used outside the block, then we
// now have to update all uses of the value to use either the original value,
// the cloned value, or some PHI derived value. This can require arbitrary
@@ -2331,8 +2364,8 @@
// And finally, do it!
LLVM_DEBUG(dbgs() << " Threading edge from '" << PredBB->getName()
- << "' to '" << SuccBB->getName()
- << ", across block:\n " << *BB << "\n");
+ << "' to '" << SuccBB->getName() << "', across block:\n "
+ << *BB << "\n");
if (DTU->hasPendingDomTreeUpdates())
LVI->disableDT();
-------------- next part --------------
A non-text attachment was scrubbed...
Name: D75799.248920.patch
Type: text/x-patch
Size: 3736 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/llvm-commits/attachments/20200307/ae3ed6af/attachment.bin>
More information about the llvm-commits
mailing list