mirror of
https://github.com/c64scene-ar/llvm-6502.git
synced 2025-01-04 21:30:49 +00:00
Instcombine's ShrinkDemandedConstant may strip bits out of constants,
obscuring what would otherwise be a low-bits mask. Use ComputeMaskedBits to compute what ShrinkDemandedConstant knew about to reconstruct a low-bits mask value. git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@73540 91177308-0d34-0410-b5e6-96231b3b80d8
This commit is contained in:
parent
876eac9da5
commit
61ffa8e373
@ -68,6 +68,7 @@
|
|||||||
#include "llvm/Analysis/ConstantFolding.h"
|
#include "llvm/Analysis/ConstantFolding.h"
|
||||||
#include "llvm/Analysis/Dominators.h"
|
#include "llvm/Analysis/Dominators.h"
|
||||||
#include "llvm/Analysis/LoopInfo.h"
|
#include "llvm/Analysis/LoopInfo.h"
|
||||||
|
#include "llvm/Analysis/ValueTracking.h"
|
||||||
#include "llvm/Assembly/Writer.h"
|
#include "llvm/Assembly/Writer.h"
|
||||||
#include "llvm/Target/TargetData.h"
|
#include "llvm/Target/TargetData.h"
|
||||||
#include "llvm/Support/CommandLine.h"
|
#include "llvm/Support/CommandLine.h"
|
||||||
@ -2394,14 +2395,28 @@ SCEVHandle ScalarEvolution::createSCEV(Value *V) {
|
|||||||
if (CI->isAllOnesValue())
|
if (CI->isAllOnesValue())
|
||||||
return getSCEV(U->getOperand(0));
|
return getSCEV(U->getOperand(0));
|
||||||
const APInt &A = CI->getValue();
|
const APInt &A = CI->getValue();
|
||||||
unsigned Ones = A.countTrailingOnes();
|
|
||||||
if (APIntOps::isMask(Ones, A))
|
// Instcombine's ShrinkDemandedConstant may strip bits out of
|
||||||
|
// constants, obscuring what would otherwise be a low-bits mask.
|
||||||
|
// Use ComputeMaskedBits to compute what ShrinkDemandedConstant
|
||||||
|
// knew about to reconstruct a low-bits mask value.
|
||||||
|
unsigned LZ = A.countLeadingZeros();
|
||||||
|
unsigned BitWidth = A.getBitWidth();
|
||||||
|
APInt AllOnes = APInt::getAllOnesValue(BitWidth);
|
||||||
|
APInt KnownZero(BitWidth, 0), KnownOne(BitWidth, 0);
|
||||||
|
ComputeMaskedBits(U->getOperand(0), AllOnes, KnownZero, KnownOne, TD);
|
||||||
|
|
||||||
|
APInt EffectiveMask = APInt::getLowBitsSet(BitWidth, BitWidth - LZ);
|
||||||
|
|
||||||
|
if (LZ != 0 && !((~A & ~KnownZero) & EffectiveMask)) {
|
||||||
return
|
return
|
||||||
getZeroExtendExpr(getTruncateExpr(getSCEV(U->getOperand(0)),
|
getZeroExtendExpr(getTruncateExpr(getSCEV(U->getOperand(0)),
|
||||||
IntegerType::get(Ones)),
|
IntegerType::get(BitWidth - LZ)),
|
||||||
U->getType());
|
U->getType());
|
||||||
|
}
|
||||||
}
|
}
|
||||||
break;
|
break;
|
||||||
|
|
||||||
case Instruction::Or:
|
case Instruction::Or:
|
||||||
// If the RHS of the Or is a constant, we may have something like:
|
// If the RHS of the Or is a constant, we may have something like:
|
||||||
// X*4+1 which got turned into X*4|1. Handle this as an Add so loop
|
// X*4+1 which got turned into X*4|1. Handle this as an Add so loop
|
||||||
|
14
test/Transforms/IndVarSimplify/shrunk-constant.ll
Normal file
14
test/Transforms/IndVarSimplify/shrunk-constant.ll
Normal file
@ -0,0 +1,14 @@
|
|||||||
|
; RUN: llvm-as < %s | opt -iv-users -analyze | grep store
|
||||||
|
|
||||||
|
define fastcc void @foo() nounwind {
|
||||||
|
entry:
|
||||||
|
br label %loop
|
||||||
|
|
||||||
|
loop:
|
||||||
|
%i = phi i32 [ 0, %entry ], [ %t2, %loop ]
|
||||||
|
%t0 = add i32 %i, 9
|
||||||
|
%t1 = and i32 %t0, 9
|
||||||
|
store i32 %t1, i32* null
|
||||||
|
%t2 = add i32 %i, 8
|
||||||
|
br label %loop
|
||||||
|
}
|
Loading…
Reference in New Issue
Block a user