forked from OSchip/llvm-project
AllocaInst can't return a null pointer. Fixes missed optimization
opportunity pointed out by Andrew Lewycky. llvm-svn: 31115
This commit is contained in:
parent
250eff20da
commit
f345008339
|
@ -31,6 +31,7 @@
|
||||||
#define DEBUG_TYPE "predsimplify"
|
#define DEBUG_TYPE "predsimplify"
|
||||||
#include "llvm/Transforms/Scalar.h"
|
#include "llvm/Transforms/Scalar.h"
|
||||||
#include "llvm/Constants.h"
|
#include "llvm/Constants.h"
|
||||||
|
#include "llvm/DerivedTypes.h"
|
||||||
#include "llvm/Instructions.h"
|
#include "llvm/Instructions.h"
|
||||||
#include "llvm/Pass.h"
|
#include "llvm/Pass.h"
|
||||||
#include "llvm/ADT/Statistic.h"
|
#include "llvm/ADT/Statistic.h"
|
||||||
|
@ -446,6 +447,7 @@ namespace {
|
||||||
void visitBranchInst(BranchInst &BI);
|
void visitBranchInst(BranchInst &BI);
|
||||||
void visitSwitchInst(SwitchInst &SI);
|
void visitSwitchInst(SwitchInst &SI);
|
||||||
|
|
||||||
|
void visitAllocaInst(AllocaInst &AI);
|
||||||
void visitLoadInst(LoadInst &LI);
|
void visitLoadInst(LoadInst &LI);
|
||||||
void visitStoreInst(StoreInst &SI);
|
void visitStoreInst(StoreInst &SI);
|
||||||
void visitBinaryOperator(BinaryOperator &BO);
|
void visitBinaryOperator(BinaryOperator &BO);
|
||||||
|
@ -712,6 +714,10 @@ void PredicateSimplifier::Forwards::visitSwitchInst(SwitchInst &SI) {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void PredicateSimplifier::Forwards::visitAllocaInst(AllocaInst &AI) {
|
||||||
|
KP.addNotEqual(Constant::getNullValue(AI.getType()), &AI);
|
||||||
|
}
|
||||||
|
|
||||||
void PredicateSimplifier::Forwards::visitLoadInst(LoadInst &LI) {
|
void PredicateSimplifier::Forwards::visitLoadInst(LoadInst &LI) {
|
||||||
Value *Ptr = LI.getPointerOperand();
|
Value *Ptr = LI.getPointerOperand();
|
||||||
KP.addNotEqual(Constant::getNullValue(Ptr->getType()), Ptr);
|
KP.addNotEqual(Constant::getNullValue(Ptr->getType()), Ptr);
|
||||||
|
|
|
@ -1,5 +1,5 @@
|
||||||
; RUN: llvm-as < %s | opt -predsimplify -instcombine -simplifycfg | llvm-dis | grep -v declare | not grep fail &&
|
; RUN: llvm-as < %s | opt -predsimplify -instcombine -simplifycfg | llvm-dis | grep -v declare | not grep fail &&
|
||||||
; RUN: llvm-as < %s | opt -predsimplify -instcombine -simplifycfg | llvm-dis | grep -v declare | grep pass | wc -l | grep 3
|
; RUN: llvm-as < %s | opt -predsimplify -instcombine -simplifycfg | llvm-dis | grep -v declare | grep -c pass | grep 4
|
||||||
|
|
||||||
void %test1(int %x) {
|
void %test1(int %x) {
|
||||||
entry:
|
entry:
|
||||||
|
@ -149,6 +149,21 @@ return:
|
||||||
ret void
|
ret void
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void %test10() {
|
||||||
|
entry:
|
||||||
|
%A = alloca int
|
||||||
|
%B = seteq int* %A, null
|
||||||
|
br bool %B, label %cond_true, label %cond_false
|
||||||
|
|
||||||
|
cond_true:
|
||||||
|
call void (...)* %fail ( )
|
||||||
|
ret void
|
||||||
|
|
||||||
|
cond_false:
|
||||||
|
call void (...)* %pass ( )
|
||||||
|
ret void
|
||||||
|
}
|
||||||
|
|
||||||
void %switch1(int %x) {
|
void %switch1(int %x) {
|
||||||
entry:
|
entry:
|
||||||
%A = seteq int %x, 10
|
%A = seteq int %x, 10
|
||||||
|
|
Loading…
Reference in New Issue