forked from OSchip/llvm-project
It is possible for several constants which aren't individually absorbing to
combine to the absorbing element. Thanks to nbjoerg on IRC for pointing this out. llvm-svn: 158399
This commit is contained in:
parent
318a89ddac
commit
409d8ae165
|
@ -629,8 +629,13 @@ static bool LinearizeExprTree(BinaryOperator *I,
|
|||
// Add any constants back into Ops, all globbed together and reduced to having
|
||||
// weight 1 for the convenience of users.
|
||||
Constant *Identity = ConstantExpr::getBinOpIdentity(Opcode, I->getType());
|
||||
if (Cst && Cst != Identity)
|
||||
if (Cst && Cst != Identity) {
|
||||
// If combining multiple constants resulted in the absorber then the entire
|
||||
// expression must evaluate to the absorber.
|
||||
if (Cst == Absorber)
|
||||
Ops.clear();
|
||||
Ops.push_back(std::make_pair(Cst, APInt(Bitwidth, 1)));
|
||||
}
|
||||
|
||||
// For nilpotent operations or addition there may be no operands, for example
|
||||
// because the expression was "X xor X" or consisted of 2^Bitwidth additions:
|
||||
|
|
|
@ -0,0 +1,11 @@
|
|||
; RUN: opt -S -reassociate < %s | FileCheck %s
|
||||
|
||||
; Check that if constants combine to an absorbing value then the expression is
|
||||
; evaluated as the absorbing value.
|
||||
define i8 @foo(i8 %x) {
|
||||
%tmp1 = or i8 %x, 127
|
||||
%tmp2 = or i8 %tmp1, 128
|
||||
ret i8 %tmp2
|
||||
; CHECK: @foo
|
||||
; CHECK: ret i8 -1
|
||||
}
|
Loading…
Reference in New Issue