[PATCH] D62025: Expand llvm.is.constant earlier

Joerg Sonnenberger via Phabricator via llvm-commits llvm-commits at lists.llvm.org
Thu May 16 12:25:40 PDT 2019


joerg created this revision.
joerg added reviewers: chandlerc, void.
Herald added a project: LLVM.

At the moment, llvm.is.constant intrinsics with non-constant arguments get expanded
during SelectionDAG preparation in the default pass order. This means that they are
expanded are the last instance of SimplifyCFG and don't result in pruning of dead
branches. This breaks when the dead branches contain assembler statements that
depends on immediate arguments. This is the middle end side of the fixes for PR41027.

This patch extends the InstSimplify pass to do this expansion as it is the last generic
simplification pass before the final SimplifyCFG and already iterating all instructions
anyway.


Repository:
  rL LLVM

https://reviews.llvm.org/D62025

Files:
  lib/Transforms/Scalar/InstSimplifyPass.cpp
  test/CodeGen/Generic/is-constant.ll


Index: test/CodeGen/Generic/is-constant.ll
===================================================================
--- test/CodeGen/Generic/is-constant.ll
+++ test/CodeGen/Generic/is-constant.ll
@@ -1,7 +1,12 @@
-; RUN: opt -O2 -S < %s  | FileCheck %s
+; RUN: opt --early-cse --inline --simplifycfg -S < %s  | FileCheck %s
 ; RUN: llc -o /dev/null 2>&1 < %s
 ; RUN: llc -O0 -o /dev/null 2>&1 < %s
 
+;; Ensure that the Simplify Instructions pass removes all remaining
+;; llvm.is.constant intrinsics.
+; RUN: opt --early-cse --inline --instsimplify --simplifycfg -S < %s  | FileCheck --check-prefix=O2 %s
+; O2-NOT: call i1 @llvm.is.constant
+
 ;; The llc runs above are just to ensure it doesn't blow up upon
 ;; seeing an is_constant intrinsic.
 
Index: lib/Transforms/Scalar/InstSimplifyPass.cpp
===================================================================
--- lib/Transforms/Scalar/InstSimplifyPass.cpp
+++ lib/Transforms/Scalar/InstSimplifyPass.cpp
@@ -17,6 +17,7 @@
 #include "llvm/IR/DataLayout.h"
 #include "llvm/IR/Dominators.h"
 #include "llvm/IR/Function.h"
+#include "llvm/IR/PatternMatch.h"
 #include "llvm/IR/Type.h"
 #include "llvm/Pass.h"
 #include "llvm/Transforms/Utils.h"
@@ -46,6 +47,15 @@
 
         // Don't waste time simplifying unused instructions.
         if (!I->use_empty()) {
+          using namespace PatternMatch;
+          if (match(I, m_Intrinsic<Intrinsic::is_constant>())) {
+            Constant *RetVal = ConstantInt::get(I->getType(), 0);
+            replaceAndRecursivelySimplify(I, RetVal, nullptr, nullptr);
+            BI = BB->begin();
+            BE = BB->end();
+            Changed = true;
+            continue;
+          }
           if (Value *V = SimplifyInstruction(I, SQ, ORE)) {
             // Mark all uses for resimplification next time round the loop.
             for (User *U : I->users())


-------------- next part --------------
A non-text attachment was scrubbed...
Name: D62025.199880.patch
Type: text/x-patch
Size: 1859 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/llvm-commits/attachments/20190516/b2d7da75/attachment.bin>


More information about the llvm-commits mailing list