This is an archive of the discontinued LLVM Phabricator instance.

[InstCombine] Fix PR37526: MinMax patterns produce an infinite loop.
ClosedPublic

Authored by ABataev on May 21 2018, 8:17 AM.

Details

Summary

This patch fixes PR37526 by simplifying the newly generated LoadInst
instructions. If the pointer address is a bitcast from the pointer to
the NewType, we can just remove this extra bitcast instead of creating
the new one. This fixes the PR37526 + may speed up the whole compilation
process.

Diff Detail

Repository
rL LLVM

Event Timeline

ABataev created this revision.May 21 2018, 8:17 AM
xbolva00 added inline comments.
lib/Transforms/InstCombine/InstCombineLoadStoreAlloca.cpp
467 ↗(On Diff #147788)

NewPtr = Op0 ?

ABataev updated this revision to Diff 147789.May 21 2018, 8:26 AM

Improved code.

spatel added inline comments.May 21 2018, 8:54 AM
lib/Transforms/InstCombine/InstCombineLoadStoreAlloca.cpp
462–467 ↗(On Diff #147789)

Use a matcher to simplify this?

Value *NewPtr;
if (!(match(Ptr, m_BitCast(m_Value(NewPtr))) &&
      NewPtr->getType()->getPointerElementType() == NewTy &&
      NewPtr->getType()->getPointerAddressSpace() == AS))
  NewPtr = IC.Builder.CreateBitCast(Ptr, NewTy->getPointerTo(AS));
test/Transforms/InstCombine/PR37526.ll
4–6 ↗(On Diff #147789)

We shouldn't need a struct or loop to repro - something like this should be ok?

define void @PR37526(i32* %pz, i32* %px, i32* %py) {
  %t1 = bitcast i32* %pz to i64*
  %t2 = load i32, i32* %py
  %t3 = load i32, i32* %px
  %cmp = icmp slt i32 %t2, %t3
  %select = select i1 %cmp, i32* %px, i32* %py
  %bc = bitcast i32* %select to i64*
  %r = load i64, i64* %bc
  store i64 %r, i64* %t1
  ret void
}
ABataev updated this revision to Diff 147808.May 21 2018, 10:04 AM

Address comments from Sanjay Patel

This revision is now accepted and ready to land.May 21 2018, 10:08 AM
This revision was automatically updated to reflect the committed changes.