Skip to content

Conversation

@antoniofrighetto
Copy link
Contributor

Importing...

…emorySSA

A logic incompleteness may lead MemorySSA to be too conservative in its results. Specifically,
when dealing with a call of kind `call i32 bitcast (i1 (i1)* @test to i32 (i32)*)(i32 %1)`,
where function call `test` is declared with `readonly` attribute, the bitcast is not wrapped,
obscuring function attributes. Hence, some methods of CallBase (e.g., `doesNotReadMemory`)
could provide incomplete results. This issue was addressed with improved checks.
@pfez
Copy link
Contributor

pfez commented Sep 17, 2021

This PR is a backport of this patch on LLVM's Phabricator which has already been accepted.

I'll give it a spin and likely merge it next week.

@revng-push-ci revng-push-ci merged commit 7a0c96e into revng:master Sep 20, 2021
@antoniofrighetto antoniofrighetto deleted the fix/memoryssa branch September 21, 2021 13:21
tvandera pushed a commit to tvandera/llvm-project that referenced this pull request Oct 5, 2021
Andrei Matei reported a llvm11 core dump for his bpf program
   https://bugs.llvm.org/show_bug.cgi?id=48578
The core dump happens in LiveVariables analysis phase.
  revng#4 0x00007fce54356bb0 __restore_rt
  revng#5 0x00007fce4d51785e llvm::LiveVariables::HandleVirtRegUse(unsigned int,
      llvm::MachineBasicBlock*, llvm::MachineInstr&)
  revng#6 0x00007fce4d519abe llvm::LiveVariables::runOnInstr(llvm::MachineInstr&,
      llvm::SmallVectorImpl<unsigned int>&)
  revng#7 0x00007fce4d519ec6 llvm::LiveVariables::runOnBlock(llvm::MachineBasicBlock*, unsigned int)
  revng#8 0x00007fce4d51a4bf llvm::LiveVariables::runOnMachineFunction(llvm::MachineFunction&)
The bug can be reproduced with llvm12 and latest trunk as well.

Futher analysis shows that there is a bug in BPF peephole
TRUNC elimination optimization, which tries to remove
unnecessary TRUNC operations (a <<= 32; a >>= 32).
Specifically, the compiler did wrong transformation for the
following patterns:
   %1 = LDW ...
   %2 = SLL_ri %1, 32
   %3 = SRL_ri %2, 32
   ... %3 ...
   %4 = SRA_ri %2, 32
   ... %4 ...

The current transformation did not check how many uses of %2
and did transformation like
   %1 = LDW ...
   ... %1 ...
   %4 = SRL_ri %2, 32
   ... %4 ...
and pseudo register %2 is used by not defined and
caused LiveVariables analysis core dump.

To fix the issue, when traversing back from SRL_ri to SLL_ri,
check to ensure SLL_ri has only one use. Otherwise, don't
do transformation.

Differential Revision: https://reviews.llvm.org/D97792

(cherry picked from commit 51cdb78)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants