This is an archive of the discontinued LLVM Phabricator instance.

[SimplifyCFG] Do not sink and merge inline-asm instructions
ClosedPublic

Authored by ahatanak on Jan 24 2017, 7:00 PM.

Details

Summary

SimplifyCFG currently transforms the following IR

if.then:
  %0 = call i32 asm "rorl $2, $0", "=&r,0,n,~{dirflag},~{fpsr},~{flags}"(i32 %r6, i32 8)
  br label %if.end

if.else:
  %1 = call i32 asm "rorl $2, $0", "=&r,0,n,~{dirflag},~{fpsr},~{flags}"(i32 %r6, i32 6)
  br label %if.end

into this IR:

%tobool = icmp eq i32 %c, 0
%.sink = select i1 %tobool, i32 6, i32 8
%0 = call i32 asm "rorl $2, $0", "=&r,0,n,~{dirflag},~{fpsr},~{flags}"(i32 %r6, i32 %.sink)

This is bad because constraint "n" expects an immediate integer operand and merging the instructions causes a crash in the backend printing the following error message:

error: invalid operand for inline asm constraint 'n'

This patch fixes the crash by conservatively disabling the transformation when the instructions to be moved are inline-asm instructions.

Diff Detail

Repository
rL LLVM

Event Timeline

ahatanak created this revision.Jan 24 2017, 7:00 PM
majnemer accepted this revision.Jan 24 2017, 9:02 PM

LGTM

lib/Transforms/Utils/SimplifyCFG.cpp
1440 ↗(On Diff #85678)

I'd mention the constraint issue, it quickly explains why this is needed.

This revision is now accepted and ready to land.Jan 24 2017, 9:02 PM
This revision was automatically updated to reflect the committed changes.
ahatanak marked an inline comment as done.