mirror of
https://github.com/c64scene-ar/llvm-6502.git
synced 2024-12-13 04:30:23 +00:00
PR9346: Prevent SimplifyDemandedBits from incorrectly introducing
INT_MIN % -1. git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@127306 91177308-0d34-0410-b5e6-96231b3b80d8
This commit is contained in:
parent
d7f3e7d046
commit
c6b018b737
@ -684,6 +684,10 @@ Value *InstCombiner::SimplifyDemandedUseBits(Value *V, APInt DemandedMask,
|
||||
break;
|
||||
case Instruction::SRem:
|
||||
if (ConstantInt *Rem = dyn_cast<ConstantInt>(I->getOperand(1))) {
|
||||
// X % -1 demands all the bits because we don't want to introduce
|
||||
// INT_MIN % -1 (== undef) by accident.
|
||||
if (Rem->isAllOnesValue())
|
||||
break;
|
||||
APInt RA = Rem->getValue().abs();
|
||||
if (RA.isPowerOf2()) {
|
||||
if (DemandedMask.ult(RA)) // srem won't affect demanded bits
|
||||
|
12
test/Transforms/InstCombine/2011-03-08-SRemMinusOneBadOpt.ll
Normal file
12
test/Transforms/InstCombine/2011-03-08-SRemMinusOneBadOpt.ll
Normal file
@ -0,0 +1,12 @@
|
||||
; RUN: opt < %s -instcombine -S | FileCheck %s
|
||||
; PR9346
|
||||
|
||||
define i32 @test(i64 %x) nounwind {
|
||||
; CHECK: ret i32 0
|
||||
entry:
|
||||
%or = or i64 %x, 4294967294
|
||||
%conv = trunc i64 %or to i32
|
||||
%rem.i = srem i32 %conv, -1
|
||||
ret i32 %rem.i
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user