[llvm-commits] [llvm] r158399 - in /llvm/trunk: lib/Transforms/Scalar/Reassociate.cpp test/Transforms/Reassociate/absorption.ll
Duncan Sands
baldrick at free.fr
Wed Jun 13 05:15:57 PDT 2012
Author: baldrick
Date: Wed Jun 13 07:15:56 2012
New Revision: 158399
URL: http://llvm.org/viewvc/llvm-project?rev=158399&view=rev
Log:
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.
Added:
llvm/trunk/test/Transforms/Reassociate/absorption.ll
Modified:
llvm/trunk/lib/Transforms/Scalar/Reassociate.cpp
Modified: llvm/trunk/lib/Transforms/Scalar/Reassociate.cpp
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/lib/Transforms/Scalar/Reassociate.cpp?rev=158399&r1=158398&r2=158399&view=diff
==============================================================================
--- llvm/trunk/lib/Transforms/Scalar/Reassociate.cpp (original)
+++ llvm/trunk/lib/Transforms/Scalar/Reassociate.cpp Wed Jun 13 07:15:56 2012
@@ -629,8 +629,13 @@
// 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:
Added: llvm/trunk/test/Transforms/Reassociate/absorption.ll
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/test/Transforms/Reassociate/absorption.ll?rev=158399&view=auto
==============================================================================
--- llvm/trunk/test/Transforms/Reassociate/absorption.ll (added)
+++ llvm/trunk/test/Transforms/Reassociate/absorption.ll Wed Jun 13 07:15:56 2012
@@ -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
+}
More information about the llvm-commits
mailing list