This is an archive of the discontinued LLVM Phabricator instance.

Fix urem instruction with power of two to compute known bit.
ClosedPublic

Authored by akuharev on May 19 2014, 5:08 AM.

Details

Summary

Recursive computeKnownBits initiates parameters KnownZero and KnownOne
at the begining so we should use KnownZero2 and KnownOne2.
We should use computation for returned Known bits.
Despite of the comments, isPowerOf2 returns true for RA is power of two = 0, i.e. RA = 1,

Diff Detail

Event Timeline

akuharev updated this revision to Diff 9525.May 19 2014, 5:08 AM
akuharev retitled this revision from to Fix urem instruction with power of two to compute known bit..
akuharev updated this object.
akuharev edited the test plan for this revision. (Show Details)
akuharev updated this object.May 19 2014, 5:13 AM
akuharev updated this revision to Diff 9604.May 20 2014, 3:48 AM
akuharev updated this object.
akuharev added a reviewer: rafael.
akuharev added a subscriber: Unknown Object (MLST).

This patch fixes bug 19636

akuharev updated this revision to Diff 9705.May 22 2014, 10:02 AM

For power of two urem similiar to and instruction

rafael accepted this revision.May 22 2014, 2:40 PM
rafael edited edge metadata.

LGTM with a code nit and a test change.

lib/CodeGen/SelectionDAG/SelectionDAG.cpp
2191

This assignment is redundant. How about just

// The upper bits are all zero, the lower ones are unchanged.
KnownOne = KnownOne2 & LowBits;
KnownZero = KnowZero2 | ~LowBits;

test/CodeGen/Generic/computeKnownBits_urem.ll
1 ↗(On Diff #9705)

This should probably also check the generated assembly. It is fine to move it to a cpu specific directory and use a -mtriple.

This revision is now accepted and ready to land.May 22 2014, 2:40 PM
akuharev updated this revision to Diff 9729.May 22 2014, 11:56 PM
akuharev edited edge metadata.

Remove redundant lines

I check asm output in new version by
llc -mtriple=i386-pc-win32 computeKnownBits_urem.ll
Result is very simple and right:

  _main:                                  # @main
  # BB#0:                                 # %entry
  	pushl	%eax
  	movl	$1, (%esp)
  	movl	$1, %eax
  	popl	%edx
  	retl

Algorithm is sufficiently complex and the same result in asm
can be obtained by the different ways with slightly different IR file.
Changed code works when simplification begins from not "urem" instruction.
Instructions "and" and "or" set KnownOne and KnownZero mutually.
Instruction "load" in computeKnownBits cuts initialization of %a.
Result of changed code work is simplification with message

Replacing.2 .......

if KnownOne and KnownZero leads to definite result
then next message is

With: 0x{{[0-9a-f]+}}: i32 = Constant ....

I don't have commit access. Thanks for the review, and please commit.

akuharev updated this revision to Diff 9790.May 25 2014, 3:06 PM

Variant with -mtriple=i386-pc-win32

akuharev updated this revision to Diff 9950.May 29 2014, 10:12 PM

Changed patch according to changed trunk

Sorry, I missed this.

I committed the patch (r209902 ). I just updated the test to check for
assembly (as opposed to just generating it).

Normally in LLVM we test that the result is valid, not exactly the
steps that a transformation is doing. Doing that gives more freedom at
modifying the passes in the future.

We do try to write small tests and test the smallest part of llvm that
we can. It is really unfortunate with codegen that such a large piece
of code needs to be run, but I don't think that checking deubg output
is the correct way to fix that.

Thanks for the explanation.

Eugene.Zelenko closed this revision.Oct 3 2016, 4:50 PM