yao via llvm-dev
2018-Apr-09 08:30 UTC
[llvm-dev] How to get the case value from Machine Instruction
Hi, guys I am interesting about how to get the switch case value form the Machine Instruction. I know the switch will be converted to jump-table in the Machine Instruction. And in the phase CodeGen , the case-value of SwitchInst can get esasly. but it seems no case -value in Machine Instruction. The MI as follows: Frame Objects: fi#0: size=1, align=0, at location [SP] fi#1: size=4, align=4, at location [SP+8] fi#2: size=4, align=4, at location [SP+4] fi#3: size=4, align=4, at location [SP] Jump Tables: %jump-table.0: %bb.2 %bb.3 %bb.4 %bb.5 %bb.0: derived from LLVM BB %0 %r0 = MOVi 0, 14, %noreg, %noreg STRi12 %r0, %stack.1, 14, %noreg %r0 = MOVi 4, 14, %noreg, %noreg STRi12 %r0, %stack.2, 14, %noreg %r0 = LDRi12 %stack.2, 14, %noreg %r0 = SUBri %r0, 1, 14, %noreg, %noreg CMPri %r0, 3, 14, %noreg, implicit-def %cpsr STRi12 %r0, %stack.3, 14, %noreg Bcc %bb.6, 8, %cpsr Successors according to CFG: %bb.6 %bb.1 %bb.1: derived from LLVM BB %1 Predecessors according to CFG: %bb.0 %1:gprnopc = LEApcrelJT %jump-table.0, 14, %noreg %2:gprnopc = LDRrs killed %0:gprnopc, %1, 0, 14, %noreg; mem:LD4[JumpTable] BR_JTr killed %2, %jump-table.0 Successors according to CFG: %bb.2(?%) %bb.3(?%) %bb.4(?%) %bb.5(?%) %bb.2: derived from LLVM BB %2 Predecessors according to CFG: %bb.1 %r0 = LDRi12 %stack.2, 14, %noreg %r0 = ADDri %r0, 11, 14, %noreg, %noreg STRi12 %r0, %stack.2, 14, %noreg B %bb.6 Successors according to CFG: %bb.6 %bb.3: derived from LLVM BB %3 Predecessors according to CFG: %bb.1 %r0 = LDRi12 %stack.2, 14, %noreg %r0 = ADDri %r0, 12, 14, %noreg, %noreg STRi12 %r0, %stack.2, 14, %noreg B %bb.6 Successors according to CFG: %bb.6 %bb.4: derived from LLVM BB %4 Predecessors according to CFG: %bb.1 %r0 = LDRi12 %stack.2, 14, %noreg %r0 = ADDri %r0, 13, 14, %noreg, %noreg STRi12 %r0, %stack.2, 14, %noreg B %bb.6 Successors according to CFG: %bb.6 %bb.5: derived from LLVM BB %5 Predecessors according to CFG: %bb.1 %r0 = LDRi12 %stack.2, 14, %noreg %r0 = ADDri %r0, 14, 14, %noreg, %noreg STRi12 %r0, %stack.2, 14, %noreg Successors according to CFG: %bb.6 %bb.6: derived from LLVM BB %6 Predecessors according to CFG: %bb.0 %bb.2 %bb.3 %bb.4 %bb.5 %r0 = LDRi12 %stack.2, 14, %noreg BX_RET 14, %noreg I hope to get the Case value from the MI, Thanks, yaoxiao -------------- next part -------------- An HTML attachment was scrubbed... URL: <http://lists.llvm.org/pipermail/llvm-dev/attachments/20180409/882c5b12/attachment-0001.html>
Martin J. O'Riordan via llvm-dev
2018-Apr-09 16:10 UTC
[llvm-dev] How to get the case value from Machine Instruction
Some glitch in the emailer? I have received this message 3 times in a row!? I think that by the time it gets as far as MI-level there is no reversible method of determining the 'case' label at all. The reason I say this, is that I have often seen optimisations that coalesce groups of values into interesting logical tests and jump-tables are completely avoided. For example, a simple range like: switch(n) { case 8: case 9: case 10: case 11: case 12: case 13: case 14: case 15: ...action... } is quite likely to become (equivalent to): if ((n & 0xFFFFFF8) == 0x00000008) ...action... so the 'case' logic of the original expression is lost; and there are other logical reductions a lot less obvious than this. I expect that at IR-level, especially pre-SCEV that the 'case' specific information might still be available but at MI-level it has already been lost. The debug information might still retain some back-association, but I am not particularly familiar with Dwarf. MartinO From: llvm-dev [mailto:llvm-dev-bounces at lists.llvm.org] On Behalf Of yao via llvm-dev Sent: 09 April 2018 09:30 To: llvmdev <llvmdev at cs.uiuc.edu> Subject: [llvm-dev] How to get the case value from Machine Instruction Hi, guys I am interesting about how to get the switch case value form the Machine Instruction. I know the switch will be converted to jump-table in the Machine Instruction. And in the phase CodeGen , the case-value of SwitchInst can get esasly. but it seems no case -value in Machine Instruction. The MI as follows: Frame Objects: fi#0: size=1, align=0, at location [SP] fi#1: size=4, align=4, at location [SP+8] fi#2: size=4, align=4, at location [SP+4] fi#3: size=4, align=4, at location [SP] Jump Tables: %jump-table.0: %bb.2 %bb.3 %bb.4 %bb.5 %bb.0: derived from LLVM BB %0 %r0 = MOVi 0, 14, %noreg, %noreg STRi12 %r0, %stack.1, 14, %noreg %r0 = MOVi 4, 14, %noreg, %noreg STRi12 %r0, %stack.2, 14, %noreg %r0 = LDRi12 %stack.2, 14, %noreg %r0 = SUBri %r0, 1, 14, %noreg, %noreg CMPri %r0, 3, 14, %noreg, implicit-def %cpsr STRi12 %r0, %stack.3, 14, %noreg Bcc %bb.6, 8, %cpsr Successors according to CFG: %bb.6 %bb.1 %bb.1: derived from LLVM BB %1 Predecessors according to CFG: %bb.0 %1:gprnopc = LEApcrelJT %jump-table.0, 14, %noreg %2:gprnopc = LDRrs killed %0:gprnopc, %1, 0, 14, %noreg; mem:LD4[JumpTable] BR_JTr killed %2, %jump-table.0 Successors according to CFG: %bb.2(?%) %bb.3(?%) %bb.4(?%) %bb.5(?%) %bb.2: derived from LLVM BB %2 Predecessors according to CFG: %bb.1 %r0 = LDRi12 %stack.2, 14, %noreg %r0 = ADDri %r0, 11, 14, %noreg, %noreg STRi12 %r0, %stack.2, 14, %noreg B %bb.6 Successors according to CFG: %bb.6 %bb.3: derived from LLVM BB %3 Predecessors according to CFG: %bb.1 %r0 = LDRi12 %stack.2, 14, %noreg %r0 = ADDri %r0, 12, 14, %noreg, %noreg STRi12 %r0, %stack.2, 14, %noreg B %bb.6 Successors according to CFG: %bb.6 %bb.4: derived from LLVM BB %4 Predecessors according to CFG: %bb.1 %r0 = LDRi12 %stack.2, 14, %noreg %r0 = ADDri %r0, 13, 14, %noreg, %noreg STRi12 %r0, %stack.2, 14, %noreg B %bb.6 Successors according to CFG: %bb.6 %bb.5: derived from LLVM BB %5 Predecessors according to CFG: %bb.1 %r0 = LDRi12 %stack.2, 14, %noreg %r0 = ADDri %r0, 14, 14, %noreg, %noreg STRi12 %r0, %stack.2, 14, %noreg Successors according to CFG: %bb.6 %bb.6: derived from LLVM BB %6 Predecessors according to CFG: %bb.0 %bb.2 %bb.3 %bb.4 %bb.5 %r0 = LDRi12 %stack.2, 14, %noreg BX_RET 14, %noreg I hope to get the Case value from the MI, Thanks, yaoxiao -------------- next part -------------- An HTML attachment was scrubbed... URL: <http://lists.llvm.org/pipermail/llvm-dev/attachments/20180409/c2c56a4f/attachment-0001.html>
yao via llvm-dev
2018-Apr-10 02:35 UTC
[llvm-dev] How to get the case value from Machine Instruction
Thanks for your help. Is there possible I can get the realily case value form the MI? For the case in https://bugs.llvm.org/show_bug.cgi?id=34902. as follows. ############################# * GCC v7.1 generated assembly ############################# ** Options: -Os -marm -march=armv7-a foo: @ args = 0, pretend = 0, frame = 0 @ frame_needed = 0, uses_anonymous_args = 0 sub r0, r0, #15 push {r4, lr} cmp r0, #5 ldrls pc, [pc, r0, asl #2] b .L1 .L4: .word .L3 .word .L5 .word .L6 .word .L7 .word .L8 .word .L9 .L3: mov r0, #5 bl func .L5: mov r0, #59 bl func .L6: movw r0, #515 bl func .L7: mov r0, #65 bl func .L8: mov r0, #8 bl func .L9: mov r0, #15 pop {r4, lr} b func .L1: pop {r4, pc} the assembly shows the value was replaced by ldrls pc, [pc, r0, asl #2], I had tried to convert the MI to DAG , but seems the jumptable seems only contain the case address, Could I calculate the value by the offset or other key method ? Thanks, yaoxiao At 2018-04-10 00:10:31, "Martin J. O'Riordan" <MartinO at theheart.ie> wrote: Some glitch in the emailer? I have received this message 3 times in a row!? I think that by the time it gets as far as MI-level there is no reversible method of determining the ‘case’ label at all. The reason I say this, is that I have often seen optimisations that coalesce groups of values into interesting logical tests and jump-tables are completely avoided. For example, a simple range like: switch(n) { case 8: case 9: case 10: case 11: case 12: case 13: case 14: case 15: ...action... } is quite likely to become (equivalent to): if ((n & 0xFFFFFF8) == 0x00000008) ...action... so the ‘case’ logic of the original expression is lost; and there are other logical reductions a lot less obvious than this. I expect that at IR-level, especially pre-SCEV that the ‘case’ specific information might still be available but at MI-level it has already been lost. The debug information might still retain some back-association, but I am not particularly familiar with Dwarf. MartinO From: llvm-dev [mailto:llvm-dev-bounces at lists.llvm.org] On Behalf Of yao via llvm-dev Sent: 09 April 2018 09:30 To: llvmdev <llvmdev at cs.uiuc.edu> Subject: [llvm-dev] How to get the case value from Machine Instruction Hi, guys I am interesting about how to get the switch case value form the Machine Instruction. I know the switch will be converted to jump-table in the Machine Instruction. And in the phase CodeGen , the case-value of SwitchInst can get esasly. but it seems no case -value in Machine Instruction. The MI as follows: Frame Objects: fi#0: size=1, align=0, at location [SP] fi#1: size=4, align=4, at location [SP+8] fi#2: size=4, align=4, at location [SP+4] fi#3: size=4, align=4, at location [SP] Jump Tables: %jump-table.0: %bb.2 %bb.3 %bb.4 %bb.5 %bb.0: derived from LLVM BB %0 %r0 = MOVi 0, 14, %noreg, %noreg STRi12 %r0, %stack.1, 14, %noreg %r0 = MOVi 4, 14, %noreg, %noreg STRi12 %r0, %stack.2, 14, %noreg %r0 = LDRi12 %stack.2, 14, %noreg %r0 = SUBri %r0, 1, 14, %noreg, %noreg CMPri %r0, 3, 14, %noreg, implicit-def %cpsr STRi12 %r0, %stack.3, 14, %noreg Bcc %bb.6, 8, %cpsr Successors according to CFG: %bb.6 %bb.1 %bb.1: derived from LLVM BB %1 Predecessors according to CFG: %bb.0 %1:gprnopc = LEApcrelJT %jump-table.0, 14, %noreg %2:gprnopc = LDRrs killed %0:gprnopc, %1, 0, 14, %noreg; mem:LD4[JumpTable] BR_JTr killed %2, %jump-table.0 Successors according to CFG: %bb.2(?%) %bb.3(?%) %bb.4(?%) %bb.5(?%) %bb.2: derived from LLVM BB %2 Predecessors according to CFG: %bb.1 %r0 = LDRi12 %stack.2, 14, %noreg %r0 = ADDri %r0, 11, 14, %noreg, %noreg STRi12 %r0, %stack.2, 14, %noreg B %bb.6 Successors according to CFG: %bb.6 %bb.3: derived from LLVM BB %3 Predecessors according to CFG: %bb.1 %r0 = LDRi12 %stack.2, 14, %noreg %r0 = ADDri %r0, 12, 14, %noreg, %noreg STRi12 %r0, %stack.2, 14, %noreg B %bb.6 Successors according to CFG: %bb.6 %bb.4: derived from LLVM BB %4 Predecessors according to CFG: %bb.1 %r0 = LDRi12 %stack.2, 14, %noreg %r0 = ADDri %r0, 13, 14, %noreg, %noreg STRi12 %r0, %stack.2, 14, %noreg B %bb.6 Successors according to CFG: %bb.6 %bb.5: derived from LLVM BB %5 Predecessors according to CFG: %bb.1 %r0 = LDRi12 %stack.2, 14, %noreg %r0 = ADDri %r0, 14, 14, %noreg, %noreg STRi12 %r0, %stack.2, 14, %noreg Successors according to CFG: %bb.6 %bb.6: derived from LLVM BB %6 Predecessors according to CFG: %bb.0 %bb.2 %bb.3 %bb.4 %bb.5 %r0 = LDRi12 %stack.2, 14, %noreg BX_RET 14, %noreg I hope to get the Case value from the MI, Thanks, yaoxiao -------------- next part -------------- An HTML attachment was scrubbed... URL: <http://lists.llvm.org/pipermail/llvm-dev/attachments/20180410/b6d4ba6a/attachment.html>