This is an archive of the discontinued LLVM Phabricator instance.

InstCombine: Fix crash on icmp of gep with addrspacecasted null
ClosedPublic

Authored by arsenm on Sep 5 2019, 10:37 AM.

Details

Diff Detail

Event Timeline

arsenm created this revision.Sep 5 2019, 10:37 AM
jdoerfert added inline comments.Sep 5 2019, 11:33 AM
lib/Transforms/InstCombine/InstCombineCompares.cpp
908

Why doesn't the NullPointerIsDefined check catch this and prevent the transformation in the first place?

arsenm marked an inline comment as done.Sep 5 2019, 11:37 AM
arsenm added inline comments.
lib/Transforms/InstCombine/InstCombineCompares.cpp
908

Because this is valid. This stripped off the addrspacecast and sees this is a cast from the invalid null in addrspace 0.

jdoerfert added inline comments.Sep 5 2019, 11:54 AM
test/Transforms/InstCombine/gep-inbounds-null.ll
223

I somehow feel we should transform this into ret i1 false instead of something we cannot lower into a constant anymore.

However, I see the problem and the fix seems fine. Could you add the following test as well and a fixme above to denote this should be ret i1 false?

define i1 @invalid_bitcast_icmp_addrspacecast_as0_null_var(i32 addrspace(5)* %ptr, i32 %idx) {
; CHECK-LABEL: @invalid_bitcast_icmp_addrspacecast_as0_null(
; CHECK-NEXT:  bb:
; CHECK-NEXT:    [[TMP2:%.*]] = icmp eq i32 addrspace(5)* [[PTR:%.*]], addrspacecast (i32* null to i32 addrspace(5)*)
; CHECK-NEXT:    ret i1 [[TMP2]]
;
bb:
  %tmp1 = getelementptr inbounds i32, i32 addrspace(5)* %ptr, i32 %idx
  %tmp2 = icmp eq i32 addrspace(5)* %tmp1, addrspacecast (i32* null to i32 addrspace(5)*)
  ret i1 %tmp2
}
arsenm marked an inline comment as done.Sep 5 2019, 12:01 PM
arsenm added inline comments.
test/Transforms/InstCombine/gep-inbounds-null.ll
223

Actually, this did fold to false in my original test. I might have broken something when I copied it into the preexisting test

arsenm updated this revision to Diff 218993.Sep 5 2019, 3:12 PM
arsenm marked 2 inline comments as done.

Add test and fixme

test/Transforms/InstCombine/gep-inbounds-null.ll
223

My original test was comparing to an alloca derived pointer, so I believe it was deleted for other reasons

jdoerfert accepted this revision.Sep 5 2019, 4:20 PM

Thx. LGTM.

This revision is now accepted and ready to land.Sep 5 2019, 4:20 PM
arsenm closed this revision.Sep 5 2019, 4:38 PM

r371146